On Apr 24, 3:24 pm, Rogerio Medeiros <arge...@gmail.com> wrote: > phones = [{area_code:'31', number:'32210412'}, > {area_code:'32', number:'32210412'}] > > lawyers = [] > phones.each do |phone| > lawyer << Lawyer.joins(:phones).where('phones.area_code = ? and > phones.number ', phone.area_code, phone.number) > end
Yes, that was the best approach I found, but it's still not the best, since it makes several SQL queries instead of only the one needed. I guess active record just isn't flexible enough to create a query such as select * from phones where (area_code, number) in (('555', '1234564'), ('533', '12345678')). Maybe that is not supported by all databases that activerecord supports? I think that approach is probably the best way to go for now. I was just hoping someone would come up with something which looks like .where([:area_code, :number] => [['31','322210412'], ...]). I have a lot of experience with SQL, but not much with activerecord. That's why the activerecord solution strikes me as a bit odd. The runtime of the multiple queries against the single one probably won't be too different if I have (area_code, number) index. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.