Skip to content

Commit

Permalink
改进关联属性绑定
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Feb 20, 2025
1 parent b0904aa commit 7490f09
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
7 changes: 1 addition & 6 deletions src/model/relation/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getRelation(array $subRelation = [], ?Closure $closure = null)
if ($relationModel) {
if (!empty($this->bindAttr)) {
// 绑定关联属性
$this->bindAttr($this->parent, $relationModel);
$this->parent->bindRelationAttr($relationModel, $this->bindAttr);
}

$relationModel->setParent(clone $this->parent);
Expand Down Expand Up @@ -258,11 +258,6 @@ protected function eagerlySet(array &$resultSet, string $relation, array $subRel
$result->bindRelationAttr($relationModel, $this->bindAttr);
} else {
$result->setRelation($relation, $relationModel);
if (!empty($this->bindAttr)) {
// 绑定关联属性
$this->bindAttr($result, $relationModel);
$result->hidden([$relation], true);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/relation/HasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getRelation(array $subRelation = [], ?Closure $closure = null)
if ($relationModel) {
if (!empty($this->bindAttr)) {
// 绑定关联属性
$this->bindAttr($this->parent, $relationModel);
$this->parent->bindRelationAttr($relationModel, $this->bindAttr);
}

$relationModel->setParent(clone $this->parent);
Expand Down

0 comments on commit 7490f09

Please sign in to comment.