mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 07:02:47 +08:00
模型的数据不受allowfield影响
This commit is contained in:
@@ -943,18 +943,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
}
|
||||
}
|
||||
|
||||
// 检测字段
|
||||
if (!empty($this->field)) {
|
||||
if (true === $this->field) {
|
||||
$this->field = $this->getQuery()->getTableInfo('', 'fields');
|
||||
}
|
||||
foreach ($this->data as $key => $val) {
|
||||
if (!in_array($key, $this->field)) {
|
||||
unset($this->data[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 数据自动完成
|
||||
$this->autoCompleteData($this->auto);
|
||||
|
||||
@@ -990,6 +978,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
$where = $this->updateWhere;
|
||||
}
|
||||
|
||||
// 检测字段
|
||||
$this->checkAllowField($data);
|
||||
|
||||
// 保留主键数据
|
||||
foreach ($this->data as $key => $val) {
|
||||
if ($this->isPk($key)) {
|
||||
@@ -1033,6 +1024,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检测字段
|
||||
$this->checkAllowField($this->data);
|
||||
|
||||
$result = $this->getQuery()->insert($this->data);
|
||||
|
||||
// 获取自动增长主键
|
||||
@@ -1066,6 +1060,20 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function checkAllowField(&$data)
|
||||
{
|
||||
if (!empty($this->field)) {
|
||||
if (true === $this->field) {
|
||||
$this->field = $this->getQuery()->getTableInfo('', 'fields');
|
||||
}
|
||||
foreach ($data as $key => $val) {
|
||||
if (!in_array($key, $this->field)) {
|
||||
unset($data[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function autoRelationUpdate($relation)
|
||||
{
|
||||
foreach ($relation as $name => $val) {
|
||||
|
||||
Reference in New Issue
Block a user