diff --git a/src/Database/Relations/DefinedConstraints.php b/src/Database/Relations/DefinedConstraints.php index 38473a50d..5689852c4 100644 --- a/src/Database/Relations/DefinedConstraints.php +++ b/src/Database/Relations/DefinedConstraints.php @@ -16,7 +16,7 @@ trait DefinedConstraints */ public function addDefinedConstraints(): void { - $args = $this->parent->getRelationDefinition($this->relationName); + $args = $this->getRelationDefinitionForDefinedConstraints(); $this->addDefinedConstraintsToRelation($this, $args); @@ -29,7 +29,7 @@ public function addDefinedConstraints(): void public function addDefinedConstraintsToRelation($relation, array $args = null) { if ($args === null) { - $args = $this->parent->getRelationDefinition($this->relationName); + $args = $this->getRelationDefinitionForDefinedConstraints(); } // Default models (belongsTo, hasOne, hasOneThrough, morphOne) @@ -70,7 +70,7 @@ public function addDefinedConstraintsToRelation($relation, array $args = null) public function addDefinedConstraintsToQuery($query, array $args = null) { if ($args === null) { - $args = $this->parent->getRelationDefinition($this->relationName); + $args = $this->getRelationDefinitionForDefinedConstraints(); } // Conditions @@ -109,4 +109,13 @@ public function addDefinedConstraintsToQuery($query, array $args = null) } } } + + /** + * getRelationDefinitionForDefinedConstraints returns the relation definition for the + * relationship context. + */ + protected function getRelationDefinitionForDefinedConstraints() + { + return $this->parent->getRelationDefinition($this->relationName); + } } diff --git a/src/Database/Relations/HasManyThrough.php b/src/Database/Relations/HasManyThrough.php index 6b86e2500..b62112f34 100644 --- a/src/Database/Relations/HasManyThrough.php +++ b/src/Database/Relations/HasManyThrough.php @@ -32,15 +32,12 @@ public function __construct(Builder $query, Model $farParent, Model $parent, $fi } /** - * {@inheritDoc} + * getRelationDefinitionForDefinedConstraints returns the relation definition for the + * relationship context. */ - public function addDefinedConstraints() + protected function getRelationDefinitionForDefinedConstraints() { - $args = $this->farParent->getRelationDefinition($this->relationName); - - $this->addDefinedConstraintsToRelation($this, $args); - - $this->addDefinedConstraintsToQuery($this, $args); + return $this->farParent->getRelationDefinition($this->relationName); } /**