【问题标题】:Laravel 5.4 from 5.3 : Error getOtherKey()来自 5.3 的 Laravel 5.4:错误 getOtherKey()
【发布时间】:2017-01-27 08:22:28
【问题描述】:

我在 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() 部分的上述代码中。

有什么替代方法吗?

【问题讨论】:

    标签: php laravel upgrade laravel-5.3 laravel-5.4


    【解决方案1】:

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

    $ownerKey = $data->getOwnerKey();
    

    【讨论】:

      猜你喜欢
      • 2017-03-18
      • 1970-01-01
      • 2017-07-12
      • 2018-04-15
      • 2017-09-03
      • 2018-04-23
      • 1970-01-01
      • 2018-03-08
      • 2017-05-30
      相关资源
      最近更新 更多