0

我在 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()

有没有其他选择?

4

1 回答 1

1

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

$ownerKey = $data->getOwnerKey();
于 2017-01-27T10:31:21.337 回答