mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 23:52:49 +08:00
改进Query类
This commit is contained in:
@@ -1717,8 +1717,8 @@ class Query
|
|||||||
* @param array|string|Query|\Closure $data
|
* @param array|string|Query|\Closure $data
|
||||||
* @return Collection|false|\PDOStatement|string
|
* @return Collection|false|\PDOStatement|string
|
||||||
* @throws DbException
|
* @throws DbException
|
||||||
* @throws Exception
|
* @throws ModelNotFoundException
|
||||||
* @throws PDOException
|
* @throws DataNotFoundException
|
||||||
*/
|
*/
|
||||||
public function select($data = null)
|
public function select($data = null)
|
||||||
{
|
{
|
||||||
@@ -1789,11 +1789,7 @@ class Query
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif (!empty($options['fail'])) {
|
} elseif (!empty($options['fail'])) {
|
||||||
if (!empty($this->model)) {
|
$this->throwNotFound($options);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $resultSet;
|
return $resultSet;
|
||||||
}
|
}
|
||||||
@@ -1804,8 +1800,8 @@ class Query
|
|||||||
* @param array|string|Query|\Closure $data
|
* @param array|string|Query|\Closure $data
|
||||||
* @return array|false|\PDOStatement|string|Model
|
* @return array|false|\PDOStatement|string|Model
|
||||||
* @throws DbException
|
* @throws DbException
|
||||||
* @throws Exception
|
* @throws ModelNotFoundException
|
||||||
* @throws PDOException
|
* @throws DataNotFoundException
|
||||||
*/
|
*/
|
||||||
public function find($data = null)
|
public function find($data = null)
|
||||||
{
|
{
|
||||||
@@ -1874,15 +1870,27 @@ class Query
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif (!empty($options['fail'])) {
|
} elseif (!empty($options['fail'])) {
|
||||||
|
$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)) {
|
if (!empty($this->model)) {
|
||||||
throw new ModelNotFoundException('model data Not Found:' . $this->model, $this->model, $options);
|
throw new ModelNotFoundException('model data Not Found:' . $this->model, $this->model, $options);
|
||||||
} else {
|
} else {
|
||||||
throw new DataNotFoundException('table data not Found:' . $options['table'], $options['table'], $options);
|
throw new DataNotFoundException('table data not Found:' . $options['table'], $options['table'], $options);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$data = null;
|
|
||||||
}
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1891,8 +1899,8 @@ class Query
|
|||||||
* @param array|string|Query|\Closure $data
|
* @param array|string|Query|\Closure $data
|
||||||
* @return array|\PDOStatement|string|Model
|
* @return array|\PDOStatement|string|Model
|
||||||
* @throws DbException
|
* @throws DbException
|
||||||
* @throws Exception
|
* @throws ModelNotFoundException
|
||||||
* @throws PDOException
|
* @throws DataNotFoundException
|
||||||
*/
|
*/
|
||||||
public function selectOrFail($data = null)
|
public function selectOrFail($data = null)
|
||||||
{
|
{
|
||||||
@@ -1905,8 +1913,8 @@ class Query
|
|||||||
* @param array|string|Query|\Closure $data
|
* @param array|string|Query|\Closure $data
|
||||||
* @return array|\PDOStatement|string|Model
|
* @return array|\PDOStatement|string|Model
|
||||||
* @throws DbException
|
* @throws DbException
|
||||||
* @throws Exception
|
* @throws ModelNotFoundException
|
||||||
* @throws PDOException
|
* @throws DataNotFoundException
|
||||||
*/
|
*/
|
||||||
public function findOrFail($data = null)
|
public function findOrFail($data = null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user