Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...