On Oct 26, 2:06 pm, Mitchell Gould <[email protected]> wrote: > Philip Hallstrom wrote: > >> find(:first, :joins => :manuf_description, :conditions => {:id => > > >> Any ideas? > > > Add an :include => :manuf_descriptions to your find call. > > Hi Philip thanks for your help. > I did as you suggested and got the following > > find(:first, :joins => :manuf_description,:include => > :manuf_description, :conditions => {:id => manufacturer_id, > :manuf_descriptions => {:locale => I18n.locale}}) > > But Rails still produced the following output which I can see in the > console: > > SELECT `manufacturers`.* FROM `manufacturers` INNER JOIN > `manuf_descriptions` ON manuf_descriptions.manufacturer_id = > manufacturers.id WHERE (`manuf_descriptions`.`locale` = 'fr' AND > `manufacturers`.`id` = '106') LIMIT 1 > > I need the descriptions column from the manuf_descriptions table so I > need the generated SQL statement to include the line as follows: > > SELECT manufacturers.*, manuf_descriptions.* FROM manufacturers INNER > JOIN manuf_descriptions ON manuf_descriptions.manufacturer_id = > manufacturers.id WHERE (manuf_descriptions.locale = fr AND > manufacturers.id = 4) > > -- > Posted viahttp://www.ruby-forum.com/.
As far as I can think, you can't easily and usefully match this exact query via ActiveRecord's API. However, to achieve what it sounds like you want (loading both the manufacturers and manuf_descriptions tables in one query), something like this seems appropriate: manufacturer = Manufacturers.first(:include => :manuf_description, :conditions => ["id = ? AND manuf_descriptions.locale = ?", manufacturer_id, locale]) Then again if you're only loading one record at a time, the overhead of the generated eager loading query *might* not outweight the cost of the second DB call when you call manufacturer.description (or whatever). --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

