改进Query类

This commit is contained in:
thinkphp
2016-07-04 15:44:08 +08:00
parent d6daa4aca8
commit 8b492e0ac0

View File

@@ -1717,8 +1717,8 @@ class Query
* @param array|string|Query|\Closure $data
* @return Collection|false|\PDOStatement|string
* @throws DbException
* @throws Exception
* @throws PDOException
* @throws ModelNotFoundException
* @throws DataNotFoundException
*/
public function select($data = null)
{
@@ -1789,11 +1789,7 @@ class Query
}
}
} elseif (!empty($options['fail'])) {
if (!empty($this->model)) {
throw new ModelNotFoundException('model data Not Found:' . $this->model, $this->model, $options);
} else {
throw new DataNotFoundException('table data not Found:' . $options['table'], $options['table'], $options);
}
$this->throwNotFound($options);
}
return $resultSet;
}
@@ -1804,8 +1800,8 @@ class Query
* @param array|string|Query|\Closure $data
* @return array|false|\PDOStatement|string|Model
* @throws DbException
* @throws Exception
* @throws PDOException
* @throws ModelNotFoundException
* @throws DataNotFoundException
*/
public function find($data = null)
{
@@ -1874,25 +1870,37 @@ class Query
}
}
} elseif (!empty($options['fail'])) {
if (!empty($this->model)) {
throw new ModelNotFoundException('model data Not Found:' . $this->model, $this->model, $options);
} else {
throw new DataNotFoundException('table data not Found:' . $options['table'], $options['table'], $options);
}
$this->throwNotFound($options);
} else {
$data = null;
}
return $data;
}
/**
* 查询失败 抛出异常
* @access public
* @param array $options 查询参数
* @throws ModelNotFoundException
* @throws DataNotFoundException
*/
protected function throwNotFound($options = [])
{
if (!empty($this->model)) {
throw new ModelNotFoundException('model data Not Found:' . $this->model, $this->model, $options);
} else {
throw new DataNotFoundException('table data not Found:' . $options['table'], $options['table'], $options);
}
}
/**
* 查找多条记录 如果不存在则抛出异常
* @access public
* @param array|string|Query|\Closure $data
* @return array|\PDOStatement|string|Model
* @throws DbException
* @throws Exception
* @throws PDOException
* @throws ModelNotFoundException
* @throws DataNotFoundException
*/
public function selectOrFail($data = null)
{
@@ -1905,8 +1913,8 @@ class Query
* @param array|string|Query|\Closure $data
* @return array|\PDOStatement|string|Model
* @throws DbException
* @throws Exception
* @throws PDOException
* @throws ModelNotFoundException
* @throws DataNotFoundException
*/
public function findOrFail($data = null)
{