mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 07:12:47 +08:00
改进Model类的has方法第二个参数支持使用数组或者闭包进行自定义条件查询
This commit is contained in:
@@ -1228,7 +1228,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* 根据关联条件查询当前模型
|
* 根据关联条件查询当前模型
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $relation 关联方法名
|
* @param string $relation 关联方法名
|
||||||
* @param string $operator 比较操作符
|
* @param mixed $operator 比较操作符
|
||||||
* @param integer $count 个数
|
* @param integer $count 个数
|
||||||
* @param string $id 关联表的统计字段
|
* @param string $id 关联表的统计字段
|
||||||
* @return Model
|
* @return Model
|
||||||
@@ -1236,6 +1236,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
public static function has($relation, $operator = '>=', $count = 1, $id = '*')
|
public static function has($relation, $operator = '>=', $count = 1, $id = '*')
|
||||||
{
|
{
|
||||||
$model = new static();
|
$model = new static();
|
||||||
|
if (is_array($operator) || $operator instanceof \Closure) {
|
||||||
|
return $model->$relation()->hasWhere($model, $operator);
|
||||||
|
}
|
||||||
return $model->$relation()->has($model, $operator, $count, $id);
|
return $model->$relation()->has($model, $operator, $count, $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user