我和Laravel5.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()部分的上述代码中。
有别的选择吗?
发布于 2017-01-27 10:31:21
getOtherKey方法已重命名为getOwnerKey。因此,您可以通过以下方式获得所有者密钥:
$ownerKey = $data->getOwnerKey();https://stackoverflow.com/questions/41889566
复制相似问题