我正在传递一个变量
numbers = ["one", "two", ["three", "four"], "five"]
到我的模型中的查询:Modelname.where(number: numbers )
但我只获得了数字attr数值等于:“one”,“two”,“five”的检索对象。
如何获得“三”和“四”对象?
答案 0 :(得分:2)
使用flatten
numbers = ["one","two",["three","four"],"five"]
some_variable = numbers.flatten
=> ["one", "two", "three", "four", "five"]
Modelname.where(number: some_variable)
答案 1 :(得分:0)
您可以使用Modelname.where(number: numbers.flatten )