简体   繁体   English

CakePHP:具有一个结果的随机查询,排除两个值

[英]CakePHP: Random query with one result, exclude two values

I try to exclude two values on a random query, but it gets ignored.我尝试在随机查询中排除两个值,但它被忽略了。 Maybe one of you can enlighten me.也许你们中的一位可以启发我。 This is my code:这是我的代码:

$random = $this->Gerde
    ->find('all', [
        'conditions' => [
            'OR' => [
                'NOT' => [
                    ['employees' => 'BLUE'],
                    ['employees' => 'RED']
                ]
            ]
        ]
    ])
    ->order('rand()')
    ->first();

I get my single random result but red and blue employees appear anyway.我得到了我的单一随机结果,但无论如何都会出现红色和蓝色员工。 Does my logic suck?我的逻辑很烂吗? Thanks in advance.提前致谢。

GregSchmidts answer was the right one. GregSchmidts 的回答是正确的。 My code looks like this now and works like a charme:我的代码现在看起来像这样,并且像魅力一样工作:

$random = $this->Gerde->find('all', ['conditions' => ['employees NOT IN' => ['BLUE','RED'] ] ])
                         ->order('rand()')
                         ->first();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM