mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
改进Model类的delete方法 支持没有主键情况下的删除操作
This commit is contained in:
@@ -991,8 +991,18 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 删除条件
|
||||||
|
$pk = $this->getPk();
|
||||||
|
if (isset($this->data[$pk])) {
|
||||||
|
$where = [$pk => $this->data[$pk]];
|
||||||
|
} elseif (!empty($this->updateWhere)) {
|
||||||
|
$where = $this->updateWhere;
|
||||||
|
} else {
|
||||||
|
$where = null;
|
||||||
|
}
|
||||||
|
|
||||||
// 删除当前模型数据
|
// 删除当前模型数据
|
||||||
$result = $this->db()->delete($this->data);
|
$result = $this->db()->where($where)->delete();
|
||||||
|
|
||||||
// 关联删除
|
// 关联删除
|
||||||
if (!empty($this->relationWrite)) {
|
if (!empty($this->relationWrite)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user