Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby ActiveRecord and sql tuple support

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.

like image 590
Kelvin Avatar asked Apr 01 '13 19:04

Kelvin


2 Answers

tupleArray = [['John', '123 Main St'],['Jane', '124 Main St']]
Person.where("(name, address) IN (#{(['(?)']*tupleArray.size).join(', ')})", *tupleArray)
like image 120
Kamran Avatar answered Nov 15 '22 14:11

Kamran


Person.where("(name, address) IN ((?))", ['John', '123 Main St'])
like image 2
Rene van Lieshout Avatar answered Nov 15 '22 12:11

Rene van Lieshout