改进Query类delete方法参数默认值为null 当参数为true的时候 表示强制删除数据

This commit is contained in:
thinkphp
2016-06-28 19:07:33 +08:00
parent 4905a84a4c
commit 438330a4b2

View File

@@ -1871,7 +1871,7 @@ class Query
* @throws Exception
* @throws PDOException
*/
public function selectOrFail($data = [])
public function selectOrFail($data = null)
{
return $this->failException(true)->select($data);
}
@@ -1885,7 +1885,7 @@ class Query
* @throws Exception
* @throws PDOException
*/
public function findOrFail($data = [])
public function findOrFail($data = null)
{
return $this->failException(true)->find($data);
}
@@ -1948,22 +1948,22 @@ class Query
/**
* 删除记录
* @access public
* @param array $data 表达式
* @param mixed $data 表达式 true 表示强制删除
* @return int
* @throws Exception
* @throws PDOException
*/
public function delete($data = [])
public function delete($data = null)
{
// 分析查询表达式
$options = $this->parseExpress();
if (!empty($data)) {
if (!is_null($data) && true !== $data) {
// AR模式分析主键条件
$this->parsePkWhere($data, $options);
}
if (empty($options['where'])) {
if (true !== $data && empty($options['where'])) {
// 如果条件为空 不进行删除操作 除非设置 1=1
throw new Exception('delete without condition');
}