Laravel 5.4 来自 5.3:错误 getOtherKey()

Laravel 5.4 from 5.3 : Error getOtherKey()

我得到了 laravel 5.3 中的关系并且工作正常:

//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() 部分的代码中。

还有其他选择吗?

getOtherKey 方法已重命名为 getOwnerKey。因此,您可以通过以下方式获取所有者密钥:

$ownerKey = $data->getOwnerKey();