Skip to content

Commit

Permalink
Improve
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed May 27, 2024
1 parent 714f305 commit 9b2ccd8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ActiveRelationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,17 @@ private function addInverseRelations(array &$result): void

if ($relatedModel instanceof ActiveRecordInterface) {
$inverseRelation = $relatedModel->relationQuery($this->inverseOf);
$relations = $inverseRelation->getMultiple() ? [$this->primaryModel] : $this->primaryModel;
$primaryModel = $inverseRelation->getMultiple() ? [$this->primaryModel] : $this->primaryModel;

foreach ($result as $relatedModel) {
$relatedModel->populateRelation($this->inverseOf, $relations);
$relatedModel->populateRelation($this->inverseOf, $primaryModel);
}
} else {
$inverseRelation = $this->getARInstance()->relationQuery($this->inverseOf);
$relations = $inverseRelation->getMultiple() ? [$this->primaryModel] : $this->primaryModel;
$primaryModel = $inverseRelation->getMultiple() ? [$this->primaryModel] : $this->primaryModel;

foreach ($result as &$relatedModel) {
$relatedModel[$this->inverseOf] = $relations;
$relatedModel[$this->inverseOf] = $primaryModel;
}
}
}
Expand Down

0 comments on commit 9b2ccd8

Please sign in to comment.