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 d5e8ed8 commit ae2312c
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/ActiveRelationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,17 @@ private function addInverseRelations(array &$result): void

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

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

foreach ($result as $i => $relatedModel) {
$result[$i][$this->inverseOf] = $inverseRelation->getMultiple()
? [$this->primaryModel]
: $this->primaryModel;
$result[$i][$this->inverseOf] = $relations;
}
}
}
Expand Down

0 comments on commit ae2312c

Please sign in to comment.