Skip to content

Commit

Permalink
Fixes bug in hasmanythrough defined constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
daftspunk committed Mar 27, 2024
1 parent d006e48 commit 0f77e23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
15 changes: 12 additions & 3 deletions src/Database/Relations/DefinedConstraints.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait DefinedConstraints
*/
public function addDefinedConstraints(): void
{
$args = $this->parent->getRelationDefinition($this->relationName);
$args = $this->getRelationDefinitionForDefinedConstraints();

$this->addDefinedConstraintsToRelation($this, $args);

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
11 changes: 4 additions & 7 deletions src/Database/Relations/HasManyThrough.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 0f77e23

Please sign in to comment.