That does not work. It's really hard to do that query if you don't use 
tuples, you'd need to do one query for each possible value. Something like

phones = []
[[31,32310512],[31,96438112]].each do |phone|
  phones += Phone..where(ddd:phone[0], number:phone[1])
end

Either that or several joins. Being able to use certain features of your 
DBMS can speed up code writting, make it more elegant and maintainable. At 
the cost of being harder to switch between DBMS. But that's already hard 
(since it's almost impossible to use activerecord without using a few SQL 
statements here and there) and really has little practical use.

I've been thinking... If Phone.where('(ddd, number) in (?)', 
 [[31,32310512],[31,96438112]]) generated the correct thing it would work 
both in mysql and postgres, but it would not work on sqlite. However, it 
doesn't work in sqlite anyways. So, what's the downside of having that 
generating the correct thing?

On Wednesday, May 22, 2013 4:47:45 PM UTC-3, Gary Weaver wrote:
>
> I was going to joke that you may as well add support for SPARQL, since for 
> some reason it comes to mind when I think of tuples, and then found 
> something that already supports SPARQL with ActiveModel: 
> https://github.com/Swirrl/tripod
>
> Does this work?
>
> Phone.where('(ddd, number) in ((?),(?))',  31,32310512, 31,96438112)
> That looks cleaner to me. If you need to send in an array:
>
> Phone.where('(ddd, number) in ((?),(?))',  *[31,32310512, 31,96438112])
>
> or your example:
>
> Phone.where('(ddd, number) in ((?),(?))',  * 
> [[31,32310512],[31,96438112]].flatten)
> and you could always construct the "(?),(?)" by counting the flattened 
> array to see how many ?'s you need.
>
>
> On Tuesday, May 21, 2013 12:12:56 PM UTC-4, Rafael Almeida wrote:
>>
>> I would very much be able to do this query with ActiveRecord:
>>
>>     SELECT `phones`.* FROM `phones` WHERE (ddd, number) in 
>> ((31,32310512),(31,96438112))
>>
>> Unfortunately, ActiveRecord gives me no way to do so with a prepared 
>> statement. The intuitive way to do it would be:
>>
>>     Phone.where('(ddd, number) in (?)',  [[31,32310512],[31,96438112]])
>>
>> that does not work, as it yields:
>>
>> SELECT `phones`.* FROM `phones`  WHERE ((ddd, number) in ('---\n- 31\n- 
>> 32310512\n','---\n- 31\n- 96438112\n'))
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to