I have two tables

manufacturers          manuf_details (details are in several languages)
id                     id
name                   manufacturer_id
.                      details
.                      locale
.

I have two models

Manufacturer           Manuf_details
has_one :manuf_detail  belongs_to :manufacturer


I want to get all the info from the manufacturers table and  the details
from the manuf_details table for a specific locale and manufacturer.

In the controller I have the following:

@manufacturer = Manufacturer.find(:first, :conditions => {:id =>
params[:id]})


In the view I have the following

<%= @manufacturer.name %>
<%= @manufacturer.manuf_detail.details%>

Rails automatically generates the sql to get the info from the details
table for the  view as in:
SELECT * FROM `manuf_descriptions` WHERE
(`manuf_descriptions`.manufacturer_id = 4) LIMIT 1

But what I need is it to generate the following:
SELECT * FROM `manuf_descriptions` WHERE
(`manuf_descriptions`.manufacturer_id = 4AND 'manuf_descriptions'.locale
= 'EN') LIMIT 1

Or if the user selected say FRENCH it would be
SELECT * FROM `manuf_descriptions` WHERE
(`manuf_descriptions`.manufacturer_id = 4AND 'manuf_descriptions'.locale
= 'FR') LIMIT 1



I tried to do a join as in the following:

find(:first, :joins => :manuf_description, :conditions => {:id =>
manufacturer_id, :manuf_descriptions => {:locale => I18n.locale}})

however this does not help because the line

<%= @manufacturer.manuf_detail.details%> in the view still gets
generated by rails into

SELECT * FROM `manuf_descriptions` WHERE
(`manuf_descriptions`.manufacturer_id = 4) LIMIT 1

How can I solve this?

Thank you in advance
-- 
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to