首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >5.3中的Laravel5.4: Error getOtherKey()

5.3中的Laravel5.4: Error getOtherKey()
EN

Stack Overflow用户
提问于 2017-01-27 08:22:28
回答 1查看 582关注 0票数 0

我和Laravel5.3的关系还不错:

代码语言:javascript
复制
//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()部分的上述代码中。

有别的选择吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-27 10:31:21

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

代码语言:javascript
复制
$ownerKey = $data->getOwnerKey();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41889566

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档