# Trouble getting child table information based on locale

**URL:** <https://www.ruby-forum.com/t/trouble-getting-child-table-information-based-on-locale/177914>\
**Category:** Rails\
**Created:** [October 26, 2009, 5:39pm UTC](https://www.ruby-forum.com/t/trouble-getting-child-table-information-based-on-locale/177914 "2009-10-26T17:39:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mitch\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@mitch\_newbie](https://www.ruby-forum.com/u/mitch_newbie)\
**Post date:** [October 26, 2009, 5:39pm UTC](https://www.ruby-forum.com/t/trouble-getting-child-table-information-based-on-locale/177914/1 "2009-10-26T17:39:03Z")

</div>

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
