Skip to content

Commit

Permalink
改进一对一关联写入
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Jan 17, 2022
1 parent 14606af commit 6f5c7f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/model/relation/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,12 @@ protected function eagerlyOne(Model $result, string $relation, array $subRelatio
$relationModel->exists(true);
}

// 设置关联属性
$result->setRelation($relation, $relationModel);

if (!empty($this->bindAttr)) {
// 绑定关联属性
$this->bindAttr($result, $relationModel);
} else {
// 设置关联属性
$result->setRelation($relation, $relationModel);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/model/relation/HasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,12 @@ protected function eagerlyOne(Model $result, string $relation, array $subRelatio
$relationModel->exists(true);
}

// 设置关联属性
$result->setRelation($relation, $relationModel);

if (!empty($this->bindAttr)) {
// 绑定关联属性
$this->bindAttr($result, $relationModel);
} else {
$result->setRelation($relation, $relationModel);
}
}

Expand Down

0 comments on commit 6f5c7f6

Please sign in to comment.