Slight tweak/document Eloquent relationship ID loading
This commit is contained in:
parent
ff9462face
commit
0bb094ba29
|
|
@ -202,16 +202,19 @@ class EloquentAdapter implements AdapterInterface
|
||||||
$property = $this->getRelationshipProperty($relationship);
|
$property = $this->getRelationshipProperty($relationship);
|
||||||
$relation = $models[0]->$property();
|
$relation = $models[0]->$property();
|
||||||
|
|
||||||
if ($relation instanceof BelongsTo || $relation instanceof BelongsToMany) {
|
// If it's a belongs-to relationship, then the ID is stored on the model
|
||||||
|
// itself, so we don't need to load anything in advance.
|
||||||
|
if ($relation instanceof BelongsTo) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
(new Collection($models))->loadMissing([
|
(new Collection($models))->loadMissing([
|
||||||
$property => function ($query) use ($relation) {
|
$property => function ($query) use ($relation) {
|
||||||
$query->select([
|
$query->select($relation->getRelated()->getKeyName());
|
||||||
$relation->getRelated()->getKeyName(),
|
|
||||||
$relation->getForeignKeyName()
|
if (! $relation instanceof BelongsToMany) {
|
||||||
]);
|
$query->addSelect($relation->getForeignKeyName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue