5.0.0 - 严重 - 未处理
模型中使用save更新,数据表中id=11不存在,模型返回 也为true直接把生成的sql在mysql中执行返回影响行数为: 0
模型中正常不应该也返回 0 而不是1吗?
,这个是不是bug?
$res = $this->allowField(true)->save($data,["id"=>$data["id"]]);
echo $this->getLastSql();输出sql:UPDATE `tabel` SET `name` = 'Test' , `update_time` = 1537264935 WHERE `id` = 11============================================= update---- 2018-08-19:08:37---
=
= 相同代码在5.0下测试结果跟预想一致 返回 0
=
= so TP5.1.23版本model中save方法应该是个BUG
============================================
PS:查看TP5.1.23源码--
thinkphp\library\think\Model.php
行数431 直接返回 true?
调用Model中save方法最终都返回 TRUE
/**
* 保存当前数据对象
* @access public
* @param array $data 数据
* @param array $where 更新条件
* @param string $sequence 自增序列名
* @return bool
*/
public function save($data = [], $where = [], $sequence = null)
{
if (is_string($data)) {
$sequence = $data;
$data = [];
}
if (!$this->checkBeforeSave($data, $where)) {
return false;
}
$result = $this->exists ? $this->updateData($where) : $this->insertData($sequence);
if (false === $result) {
return false;
}
// 写入回调
$this->trigger('after_write');
// 重新记录原始数据
$this->origin = $this->data;
return true;
} 