简体   繁体   中英

Using not equal to in where clause cakephp

Why doesn't this work?

I want to display files which are

  1. available (in my case is = 0)
  2. everyone (Privacy settings which in my case is =1)
  3. Not equal to the author of the file

it doesn't display me anything for which the user that created it, it is supposed to show a file that is within those conditions

it seems like I have a problem within the 'Files.user_id !=' => $auth->user_id but I can't figure out what is wrong with it

$filesTable->find('all')->where(['available' => 0,'Privacy.privacy_id' => 1,'Files.user_id !=' => $auth->user_id])->contain(['Users','Privacy'])->toArray();

Neither of these are being displayed click here

To include null IDs in your query, you need to match on that explicitly:

$filesTable->find('all')->where([
    'available' => 0,
    'Privacy.privacy_id' => 1,
    'OR' => [
        'Files.user_id !=' => $auth->user_id,
        'Files.user_id IS' => null,
    ],
])->contain(['Users','Privacy'])->toArray();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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