# AR finder with include only specific value

**URL:** <https://www.ruby-forum.com/t/ar-finder-with-include-only-specific-value/173451>\
**Category:** Rails\
**Created:** [August 9, 2009, 12:22pm UTC](https://www.ruby-forum.com/t/ar-finder-with-include-only-specific-value/173451 "2009-08-09T12:22:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aldoitalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@aldoitalo](https://www.ruby-forum.com/u/aldoitalo)\
**Post date:** [August 9, 2009, 12:22pm UTC](https://www.ruby-forum.com/t/ar-finder-with-include-only-specific-value/173451/1 "2009-08-09T12:22:17Z")

</div>

i have a model :user with an association has\_many :langs.

table langs have fields title and langcode.

In practice every users have many langs, i retrieve specific lang with  
the langcode (en, de, fr, it, es, etc.)

Now i want to display list users with the only default lang (en), i have  
used this query:

@users = User.find(:all, :include =\> :langs)

and on wiew this:

\<% for item in @users %\>

\<%=h item.langs.first.title %\> \<%=h item.langs.first.langcode %\> \<% end %\>

but this don’t display selected items by default value langcode (“en”).  
how can i select only the “en” langcode from my query?

---

<div class="post-metadata">

**Author:** ![aldoitalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@aldoitalo](https://www.ruby-forum.com/u/aldoitalo)\
**Post date:** [August 9, 2009, 1:47pm UTC](https://www.ruby-forum.com/t/ar-finder-with-include-only-specific-value/173451/2 "2009-08-09T13:47:05Z")

</div>

> 

i have tryed with :

@users = User.find(:all, :include =\> :langs, , :conditions =\>  
[‘langs.langcode = ?’, “en”])

but never happen.

---

<div class="post-metadata">

**Author:** ![aldoitalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@aldoitalo](https://www.ruby-forum.com/u/aldoitalo)\
**Post date:** [August 9, 2009, 2:16pm UTC](https://www.ruby-forum.com/t/ar-finder-with-include-only-specific-value/173451/3 "2009-08-09T14:16:46Z")

</div>

finally i solved with this:

@users = User.find(:all, :include =\> :langs)

and on wiew modified with:

\<%=h item.langs.find\_by\_langcode(I18n.default\_locale.to\_s).title %\> \<%=h item.langs.find\_by\_langcode(I18n.default\_locale.to\_s).langcode %\>

this solution work, i hope right also in terms of performances
