新增子查询方法 addSelectSub
This commit is contained in:
parent
e105492d27
commit
727640396e
@ -166,11 +166,17 @@ class CatchQuery extends Query
|
|||||||
* 额外的字段
|
* 额外的字段
|
||||||
*
|
*
|
||||||
* @time 2020年01月13日
|
* @time 2020年01月13日
|
||||||
* @param array $fields
|
* @param $fields
|
||||||
* @return CatchQuery
|
* @return CatchQuery
|
||||||
*/
|
*/
|
||||||
public function addFields(array $fields): CatchQuery
|
public function addFields($fields): CatchQuery
|
||||||
{
|
{
|
||||||
|
if (is_string($fields)) {
|
||||||
|
$this->options['field'][] = $fields;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
$this->options['field'] = array_merge($this->options['field'], $fields);
|
$this->options['field'] = array_merge($this->options['field'], $fields);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -205,4 +211,19 @@ class CatchQuery extends Query
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增 Select 子查询
|
||||||
|
*
|
||||||
|
* @time 2020年06月17日
|
||||||
|
* @param callable $callable
|
||||||
|
* @param string $as
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function addSelectSub(callable $callable, string $as)
|
||||||
|
{
|
||||||
|
$this->field(sprintf('%s as %s', $callable($this)->buildSql(), $as));
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace catcher\traits\db;
|
namespace catcher\traits\db;
|
||||||
|
|
||||||
|
use catchAdmin\permissions\model\Users;
|
||||||
|
|
||||||
trait BaseOptionsTrait
|
trait BaseOptionsTrait
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -13,7 +15,9 @@ trait BaseOptionsTrait
|
|||||||
public function getList()
|
public function getList()
|
||||||
{
|
{
|
||||||
return $this->catchSearch()
|
return $this->catchSearch()
|
||||||
|
->field('*')
|
||||||
->catchOrder()
|
->catchOrder()
|
||||||
|
->creator()
|
||||||
->paginate();
|
->paginate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user