如何使用where从多维数组中检索值

时间:2015-07-26 11:52:51

标签: ruby-on-rails activerecord where

我正在传递一个变量

numbers = ["one", "two", ["three", "four"], "five"]

到我的模型中的查询:Modelname.where(number: numbers )但我只获得了数字attr数值等于:“one”,“two”,“five”的检索对象。

如何获得“三”和“四”对象?

2 个答案:

答案 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 )