mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进关联save方法
This commit is contained in:
@@ -202,9 +202,15 @@ class HasMany extends Relation
|
|||||||
*/
|
*/
|
||||||
public function save($data)
|
public function save($data)
|
||||||
{
|
{
|
||||||
$model = $this->make($data);
|
if ($data instanceof Model) {
|
||||||
|
$data = $data->getData();
|
||||||
|
}
|
||||||
|
|
||||||
return $model->save() ? $model : false;
|
// 保存关联表数据
|
||||||
|
$data[$this->foreignKey] = $this->parent->{$this->localKey};
|
||||||
|
|
||||||
|
$model = new $this->model();
|
||||||
|
return $model->save($data) ? $model : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -245,7 +245,17 @@ class MorphMany extends Relation
|
|||||||
*/
|
*/
|
||||||
public function save($data)
|
public function save($data)
|
||||||
{
|
{
|
||||||
$model = $this->make($data);
|
if ($data instanceof Model) {
|
||||||
|
$data = $data->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存关联表数据
|
||||||
|
$pk = $this->parent->getPk();
|
||||||
|
|
||||||
|
$data[$this->morphKey] = $this->parent->$pk;
|
||||||
|
$data[$this->morphType] = $this->type;
|
||||||
|
|
||||||
|
$model = new $this->model();
|
||||||
|
|
||||||
return $model->save() ? $model : false;
|
return $model->save() ? $model : false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,7 +199,17 @@ class MorphOne extends Relation
|
|||||||
*/
|
*/
|
||||||
public function save($data)
|
public function save($data)
|
||||||
{
|
{
|
||||||
$model = $this->make($data);
|
if ($data instanceof Model) {
|
||||||
|
$data = $data->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存关联表数据
|
||||||
|
$pk = $this->parent->getPk();
|
||||||
|
|
||||||
|
$data[$this->morphKey] = $this->parent->$pk;
|
||||||
|
$data[$this->morphType] = $this->type;
|
||||||
|
|
||||||
|
$model = new $this->model();
|
||||||
|
|
||||||
return $model->save() ? $model : false;
|
return $model->save() ? $model : false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user