阿刚

阿刚

开心做事,快乐做人!

  • 财富值160
  • 威望值0
  • 总积分290

个人信息

  • 发布了话题
    Yii2 项目如何做压力测试?
  • 回复了 的回答

    还有一种写法:

    $query->andWhere(new OrCondition([
        new InCondition('type', 'in', $types),
        ['like', 'name', '%good%'],
        'disabled=false'
    ]));
    

    点击:配合数据库工作,查找关键字:OrCondition

    看了下源码,['OR', 操作数1, 操作数2, ...] 最后转换就是用到就是用到类OrCondition

    相关文件及关键代码:
    文件:Class yii\db\QueryBuilder

    代码:

        /**
         * Contains array of default condition classes. Extend this method, if you want to change
         * default condition classes for the query builder. See [[conditionClasses]] docs for details.
         *
         * @return array
         * @see conditionClasses
         * @since 2.0.14
         */
        protected function defaultConditionClasses()
        {
            return [
                'NOT' => 'yii\db\conditions\NotCondition',
                'AND' => 'yii\db\conditions\AndCondition',
                'OR' => 'yii\db\conditions\OrCondition',
                'BETWEEN' => 'yii\db\conditions\BetweenCondition',
                'NOT BETWEEN' => 'yii\db\conditions\BetweenCondition',
                'IN' => 'yii\db\conditions\InCondition',
                'NOT IN' => 'yii\db\conditions\InCondition',
                'LIKE' => 'yii\db\conditions\LikeCondition',
                'NOT LIKE' => 'yii\db\conditions\LikeCondition',
                'OR LIKE' => 'yii\db\conditions\LikeCondition',
                'OR NOT LIKE' => 'yii\db\conditions\LikeCondition',
                'EXISTS' => 'yii\db\conditions\ExistsCondition',
                'NOT EXISTS' => 'yii\db\conditions\ExistsCondition',
            ];
        }
    

    够深入,赞一个!

  • 2019-08-21 已签到
    连续签到2天,获得了10个金钱
  • 关注了
  • 赞了回答

    我觉得可以这样写:

    $query->andFilterWhere([
        'OR', 
        ['id' => $this->location_id], 
        ['area_id' => $this->location_id], 
        ['city_id' => $this->location_id], 
        ['province_id' => $this->location_id]
    ]);
    
  • 提出了问题
    这个查询有得优化吗?
  • 2019-08-20 已签到
    连续签到1天,获得了5个金钱
  • 2019-08-16 已签到
    连续签到1天,获得了5个金钱
  • 2019-04-30 已签到
    连续签到1天,获得了5个金钱
  • 2019-03-20 已签到
    连续签到2天,获得了10个金钱
见习主管 等级规则
290/500
资料完整度
60/100
用户活跃度
10/100

Ta的关注

13

Ta的粉丝

2

Ta的访客

46