Fix #1300 relation_return_type must take precedence if it is defined (#1394)

This commit is contained in:
Menthol
2024-02-08 09:48:26 +01:00
committed by GitHub
parent 9343d3a1cc
commit cee441c87c
6 changed files with 85 additions and 4 deletions
+12 -4
View File
@@ -753,9 +753,14 @@ class ModelsCommand extends Command
get_class($relationObj->getRelated())
);
$relationReturnType = $this->getRelationReturnTypes()[$relation] ?? false;
if (
strpos(get_class($relationObj), 'Many') !== false ||
($this->getRelationReturnTypes()[$relation] ?? '') === 'many'
$relationReturnType === 'many' ||
(
!$relationReturnType &&
strpos(get_class($relationObj), 'Many') !== false
)
) {
//Collection or array of models (because Collection is Arrayable)
$relatedClass = '\\' . get_class($relationObj->getRelated());
@@ -782,8 +787,11 @@ class ModelsCommand extends Command
);
}
} elseif (
$relation === 'morphTo' ||
($this->getRelationReturnTypes()[$relation] ?? '') === 'morphTo'
$relationReturnType === 'morphTo' ||
(
!$relationReturnType &&
$relation === 'morphTo'
)
) {
// Model isn't specified because relation is polymorphic
$this->setProperty(