Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何从Arel阵列中链接或删除_Sql_Ruby On Rails_Activerecord_Arel - Fatal编程技术网

Sql 如何从Arel阵列中链接或删除

Sql 如何从Arel阵列中链接或删除,sql,ruby-on-rails,activerecord,arel,Sql,Ruby On Rails,Activerecord,Arel,我读书 没关系 如何像上面那样连锁?使用每个或地图等 user = User.arel_table foo = [ user[:id].eq(1), user[:id].eq(2), user[:id].eq(3) ] result = foo.map{|o| ??? } 使用reduce: conditions = foo.reduce(:or) User.where(conditions) 在您的情况下,它可以是: User.where(id: [1, 2, 3]) 上

我读书

没关系

如何像上面那样连锁?使用
每个
地图

user = User.arel_table

foo = [
  user[:id].eq(1),
  user[:id].eq(2),
  user[:id].eq(3)
]

result = foo.map{|o| ??? }

使用
reduce

conditions = foo.reduce(:or)
User.where(conditions)
在您的情况下,它可以是:

User.where(id: [1, 2, 3])
上面的代码在(1,2,3)中构造了其中的id查询

User.where(id: [1, 2, 3])