修正软删除

This commit is contained in:
thinkphp
2017-04-07 17:47:10 +08:00
parent b65592c9c5
commit f1366f7833

View File

@@ -30,7 +30,7 @@ trait SoftDelete
{ {
$model = new static(); $model = new static();
$field = $model->getDeleteTimeField(true); $field = $model->getDeleteTimeField(true);
return $model->db(false); return $model->getQuery();
} }
/** /**
@@ -42,7 +42,7 @@ trait SoftDelete
{ {
$model = new static(); $model = new static();
$field = $model->getDeleteTimeField(true); $field = $model->getDeleteTimeField(true);
return $model->db(false) return $model->getQuery()
->useSoftDelete($field, ['not null', '']); ->useSoftDelete($field, ['not null', '']);
} }
@@ -64,7 +64,7 @@ trait SoftDelete
$this->data[$name] = $this->autoWriteTimestamp($name); $this->data[$name] = $this->autoWriteTimestamp($name);
$result = $this->isUpdate()->save(); $result = $this->isUpdate()->save();
} else { } else {
$result = $this->db(false)->delete($this->data); $result = $this->getQuery()->delete($this->data);
} }
$this->trigger('after_delete', $this); $this->trigger('after_delete', $this);
@@ -117,7 +117,7 @@ trait SoftDelete
$where[$pk] = $this->getData($pk); $where[$pk] = $this->getData($pk);
} }
// 恢复删除 // 恢复删除
return $this->db(false) return $this->getQuery()
->useSoftDelete($name, ['not null', '']) ->useSoftDelete($name, ['not null', ''])
->where($where) ->where($where)
->update([$name => null]); ->update([$name => null]);