Proper syntax and use cases for MetaWhere in_all and in_any
-
30-05-2021 - |
Question
I've been exploring the capabilities of MetaWhere
over the last couple of days. Most of the predications are pretty straightforward, but I'm stuck on how to use in_all
and in_any
.
Here are some of my attempts:
Group.where(:id.in_any => [1,2,3])
=> SELECT `groups`.* FROM `groups` WHERE ((`groups`.`id` IN (1) OR `groups`.`id` IN (2) OR `groups`.`id` IN (3)))
Group.where(:id.in_any => [[1,2,3],[4,5,6],[7,8,9]])
=> undefined method 'visit_Fixnum' for #<MetaWhere::Visitors::Predicate:0x3740ba0>
Group.where(:id.in_any => [["1","2","3"],["4","5","6"],["7","8","9"]])
=> SELECT `groups`.* FROM `groups` WHERE (('1' AND '4' AND '7'))
Group.where(:id.in_any => ["(1,2,3)","(4,5,6)","(7,8,9)"])
=> SELECT `groups`.* FROM `groups` WHERE ((`groups`.`id` IN (0) OR `groups`.`id` IN (0) OR `groups`.`id` IN (0)))
Group.where(:id.in_any => ["1,2,3","4,5,6","7,8,9"])
=> SELECT `groups`.* FROM `groups` WHERE ((`groups`.`id` IN (1) OR `groups`.`id` IN (4) OR `groups`.`id` IN (7)))
I'm assuming they're supposed to AND
or OR
a bunch of IN
clauses, but I can't figure out how to set them up properly, nor have I been able to find any decent documentation. And if anyone has any examples of situations where these predications would be useful, that would be appreciated as well.
Solution
Sometimes, it helps to go straight to the source. Looks like there's bug: https://twitter.com/#!/erniemiller/status/191151541342830592
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow