【问题标题】:How can be add orWhere conditions in cakephp3.7 because in 3.7 orWhere deprecated如何在 cakephp3.7 中添加 orWhere 条件,因为在 3.7 orWhere 中已弃用
【发布时间】:2019-10-15 03:12:04
【问题描述】:

cakephp3.7 中的 orWhere 条件,因为在 3.7 中 orWhere 已弃用

select * from Users where Users.state = 'UP' Or (Users.status =1 and Users.role=2)

【问题讨论】:

    标签: sql cakephp conditional-statements cakephp-3.7


    【解决方案1】:

    您可以在嵌套数组语法中使用OR 关键字(为了更好的可读性,可选的AND 关键字):

    $query->where([
        'OR' => [
            'Users.state' => 'UP',
            'AND' => [
                'Users.status' => 1,
                'Users.role' => 2
            ]
        ]
    ]);
    

    或表达式:

    $query->where(function (
        \Cake\Database\Expression\QueryExpression $exp,
        \Cake\ORM\Query $query
    ) {
        return $exp->or_([
            'Users.state' => 'UP',
            $query->newExpr()->and_([
                'Users.status' => 1,
                'Users.role' => 2
            ])
        ]);
    });
    

    另见

    【讨论】:

      猜你喜欢
      • 2020-10-03
      • 1970-01-01
      • 1970-01-01
      • 2018-12-02
      • 2012-02-24
      • 2021-10-10
      • 2015-02-26
      • 1970-01-01
      • 2021-12-03
      相关资源
      最近更新 更多