0

how i can create a query for next case: i have few types: posts, comments, users and other And need search by room_id IN(1,2,3,4) and query = *** But if field room_id not exist - just skip it. For example type "user" without room_id and i whant select all user data only by query. But if this field exist - then check room_id

I use PHP + Yii2, but native code will be ok too

How create this query? Thanks

PS: more simple description need select data from different types, by different conditions Example: Select * from post, comment, user where (post.id > 10 OR comment.count <30 OR user.age = 15) AND title = 'test'

DedMorozzz
  • 342
  • 2
  • 15
  • 1
    Possible duplicate question with this one: http://stackoverflow.com/questions/25552321. IMHO the first answer should help you. – Andrzej Martyna Jul 28 '16 at 20:01

1 Answers1

0
'filter' => [
  'or' => [
    ['missing' => ['field' => 'room_id']],
    ['terms' => ['room_id' => $roomIds]]
  ],
]

it`s works correct

DedMorozzz
  • 342
  • 2
  • 15