diff --git a/src/Database/Concerns/HasRelationships.php b/src/Database/Concerns/HasRelationships.php index 881adf6b..59e2d355 100644 --- a/src/Database/Concerns/HasRelationships.php +++ b/src/Database/Concerns/HasRelationships.php @@ -259,13 +259,21 @@ public function getRelationTypeDefinitions(string $type, bool $includeMethods = */ public function getRelationTypeDefinition(string $type, string $name, bool $includeMethods = true): array|null { - $definitions = $this->getRelationTypeDefinitions($type, $includeMethods); + if (!array_key_exists($type, static::$relationTypes)) { + return null; + } - if (isset($definitions[$name])) { - return $definitions[$name]; + if ($includeMethods && $this->getRelationMethodType($name) === $type) { + return $this->relationMethodDefinition($name); } - return null; + if (!isset($this->{$type}[$name])) { + return null; + } + + $relation = $this->{$type}[$name]; + + return is_string($relation) ? [$relation] : $relation; } /** @@ -301,7 +309,7 @@ public function getRelationType(string $name, bool $includeMethods = true): ?str } foreach (array_keys(static::$relationTypes) as $type) { - if ($this->getRelationTypeDefinition($type, $name, $includeMethods) !== null) { + if (isset($this->{$type}[$name])) { return $type; } }