改进关联的save方法

This commit is contained in:
thinkphp
2018-12-11 11:14:16 +08:00
parent 4cbc0b5e93
commit d1a887cad7
3 changed files with 9 additions and 4 deletions

View File

@@ -202,7 +202,9 @@ class HasMany extends Relation
*/
public function save($data)
{
$model = $this->make($data);
$model = $this->make();
$data = array_merge($model->getData(), $data);
return $model->save($data) ? $model : false;
}

View File

@@ -245,7 +245,8 @@ class MorphMany extends Relation
*/
public function save($data)
{
$model = $this->make($data);
$model = $this->make();
$data = array_merge($model->getData(), $data);
return $model->save($data) ? $model : false;
}

View File

@@ -199,8 +199,10 @@ class MorphOne extends Relation
*/
public function save($data)
{
$model = $this->make($data);
return $model->save() ? $model : false;
$model = $this->make();
$data = array_merge($model->getData(), $data);
return $model->save($data) ? $model : false;
}
/**