问题
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