简体   繁体   English

从5.3开始的Laravel 5.4:错误getOtherKey()

[英]Laravel 5.4 from 5.3 : Error getOtherKey()

I was getting the relationship as in laravel 5.3 and was working fine: 我正在获得与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);

}

Now i downloaded fresh laravel 5.4 and it gives me error : 现在我下载了新的laravel 5.4 ,它给了我错误:

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

As the getOtherKey() exists in the above code in if() section. 由于getOtherKey()存在于if()部分的上述代码中。

Is there any alternative for that ? 还有其他选择吗?

The getOtherKey method has been renamed to getOwnerKey . getOtherKey方法已重命名为getOwnerKey So you can get the owner key by saying: 因此,您可以通过说出所有者密钥:

$ownerKey = $data->getOwnerKey();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM