Ruby ActiveRecord and sql tuple support

一曲冷凌霜 提交于 2019-12-14 00:23:40

问题


Does ActiveRecord support tuples in the where clause, assuming the underlying database does?

The resulting where clause would look something like:

where (name, address) in (('John', '123 Main St'))

I tried:

Person.where({[:name, :address] => ['John', '123 Main St']})

and it didn't work.


回答1:


tupleArray = [['John', '123 Main St'],['Jane', '124 Main St']]
Person.where("(name, address) IN (#{(['(?)']*tupleArray.size).join(', ')})", *tupleArray)



回答2:


Person.where("(name, address) IN ((?))", ['John', '123 Main St'])


来源:https://stackoverflow.com/questions/15750234/ruby-activerecord-and-sql-tuple-support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!