mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 15:02:47 +08:00
修正Relation的save方法
This commit is contained in:
@@ -158,8 +158,8 @@ class Relation
|
|||||||
$data = $this->eagerlyOneToMany($model, [
|
$data = $this->eagerlyOneToMany($model, [
|
||||||
$foreignKey => [
|
$foreignKey => [
|
||||||
'in',
|
'in',
|
||||||
$range
|
$range,
|
||||||
]
|
],
|
||||||
], $relation, $subRelation, $closure);
|
], $relation, $subRelation, $closure);
|
||||||
|
|
||||||
// 关联数据封装
|
// 关联数据封装
|
||||||
@@ -186,8 +186,8 @@ class Relation
|
|||||||
$data = $this->eagerlyManyToMany($model, [
|
$data = $this->eagerlyManyToMany($model, [
|
||||||
'pivot.' . $foreignKey => [
|
'pivot.' . $foreignKey => [
|
||||||
'in',
|
'in',
|
||||||
$range
|
$range,
|
||||||
]
|
],
|
||||||
], $relation, $subRelation);
|
], $relation, $subRelation);
|
||||||
|
|
||||||
// 关联数据封装
|
// 关联数据封装
|
||||||
@@ -465,14 +465,14 @@ class Relation
|
|||||||
*/
|
*/
|
||||||
public function save($data, array $pivot = [])
|
public function save($data, array $pivot = [])
|
||||||
{
|
{
|
||||||
if ($data instanceof Model) {
|
|
||||||
$data = $data->toArray();
|
|
||||||
}
|
|
||||||
// 判断关联类型
|
// 判断关联类型
|
||||||
switch ($this->type) {
|
switch ($this->type) {
|
||||||
case self::HAS_ONE:
|
case self::HAS_ONE:
|
||||||
case self::BELONGS_TO:
|
case self::BELONGS_TO:
|
||||||
case self::HAS_MANY:
|
case self::HAS_MANY:
|
||||||
|
if ($data instanceof Model) {
|
||||||
|
$data = $data->toArray();
|
||||||
|
}
|
||||||
// 保存关联表数据
|
// 保存关联表数据
|
||||||
$data[$this->foreignKey] = $this->parent->{$this->localKey};
|
$data[$this->foreignKey] = $this->parent->{$this->localKey};
|
||||||
$model = new $this->model;
|
$model = new $this->model;
|
||||||
|
|||||||
Reference in New Issue
Block a user