Gleb Mazovetskiy wrote: > def A > belongs_to B > belongs_to C > end > > I want to select all the A where a.b.name LIKE "x" and a.c.name LIKE Y. > Is it possible to do this with one SQL statement?
Sure: SELECT * from a LEFT JOIN b ON b.id = a.b_id LEFT JOIN c ON c.id = a.c_id WHERE b.name LIKE 'X' -- did you mean '%X%'? AND c.name LIKE 'Y' Writing a suitable ActiveRecord find statement is left as an exercise to the student. :) Best, -- Marnen Laibow-Koser http://www.marnen.org [email protected] -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

