mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进模型数据验证
This commit is contained in:
@@ -1043,15 +1043,17 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
}
|
||||
|
||||
// 数据自动验证
|
||||
if (!$this->validateData($data)) {
|
||||
return false;
|
||||
if (!empty($data)) {
|
||||
if (!$this->validateData($data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 数据对象赋值
|
||||
foreach ($data as $key => $value) {
|
||||
$this->setAttr($key, $value, $data);
|
||||
}
|
||||
}
|
||||
|
||||
// 数据对象赋值
|
||||
foreach ($data as $key => $value) {
|
||||
$this->setAttr($key, $value, $data);
|
||||
}
|
||||
|
||||
if (!empty($where)) {
|
||||
$this->isUpdate = true;
|
||||
$this->updateWhere = $where;
|
||||
|
||||
@@ -202,10 +202,9 @@ class HasMany extends Relation
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
$model = $this->make();
|
||||
$data = array_merge($model->getData(), $data);
|
||||
$model = $this->make($data);
|
||||
|
||||
return $model->save($data) ? $model : false;
|
||||
return $model->save() ? $model : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -245,10 +245,9 @@ class MorphMany extends Relation
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
$model = $this->make();
|
||||
$data = array_merge($model->getData(), $data);
|
||||
$model = $this->make($data);
|
||||
|
||||
return $model->save($data) ? $model : false;
|
||||
return $model->save() ? $model : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -199,10 +199,9 @@ class MorphOne extends Relation
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
$model = $this->make();
|
||||
$data = array_merge($model->getData(), $data);
|
||||
$model = $this->make($data);
|
||||
|
||||
return $model->save($data) ? $model : false;
|
||||
return $model->save() ? $model : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user