2017-01-27 11 views
0

я получал отношения, как в Laravel 5.3 и работает нормально:Laravel 5.4 из 5.3: getOtherKey Error()

//execute the relation of the given model 
$data = $model->{$info["relation"]}(); 

// get the type of the relation 
$class = get_class($data); 
$dataType = explode("\\", $class); 
$relationType = end($dataType); 

$options["columns"][$key]["relationType"] = $relationType; 

// if its a simple belongs-to statement 
if($relationType == "BelongsTo") { 

    // get all belongs-to query info 
    $otherTable = $data->getRelated()->getTable(); 
    $foreignKey = $data->getQualifiedForeignKey(); 
    $otherKey = $data->getOtherKey(); 

    // manually join using it 
    $retrievedRecords->leftJoin($otherTable . ' as ' . $info["relation"], $info["relation"] . '.' . $otherKey, '=', $foreignKey); 

} else if($relationType == "HasMany" || $relationType == "HasOne") { 

    // get all has-many query info 
    $otherTable = $data->getRelated()->getTable(); 
    $foreignKey = $data->getPlainForeignKey(); 
    $parentKey = $data->getQualifiedParentKeyName(); 

    // manually join using it 
    $retrievedRecords->leftJoin($otherTable . ' as ' . $info["relation"], $info["relation"] . '.' . $foreignKey, '=', $parentKey); 

} 

Теперь я скачал свежий laravel 5.4, и это дает мне ошибку:

Call to undefined method Illuminate\Database\Query\Builder::getOtherKey()

Как getOtherKey() в вышеуказанном коде в if() разделе.

Есть ли альтернатива этому?

ответ

1

Метод getOtherKey был переименован в getOwnerKey. Таким образом, вы можете получить ключ от владельца, указав:

$ownerKey = $data->getOwnerKey();