改进模型数据验证

This commit is contained in:
thinkphp
2018-12-11 12:11:29 +08:00
parent d1a887cad7
commit e0c8c71190
4 changed files with 15 additions and 16 deletions

View File

@@ -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;

View File

@@ -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;
}
/**

View File

@@ -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;
}
/**

View File

@@ -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;
}
/**