# Has\_many :through , extra data retrieval

**URL:** <https://www.ruby-forum.com/t/has-many-through-extra-data-retrieval/167811>\
**Category:** Rails\
**Created:** [May 12, 2009, 9:16pm UTC](https://www.ruby-forum.com/t/has-many-through-extra-data-retrieval/167811 "2009-05-12T21:16:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [May 12, 2009, 9:16pm UTC](https://www.ruby-forum.com/t/has-many-through-extra-data-retrieval/167811/1 "2009-05-12T21:16:09Z")

</div>

I have a has\_many :through companies \<-\> markets with emails as the  
join table.

The view is relatively easy:

\<% form\_for :market, :html =\> { :id =\> ‘marketform’ } do |f|%\>  
\<%= hidden\_field\_tag “company[companyid]”, @company.id, :index =\>  
@company.id %\>  
\<% for market in @markets %\>

  
\<%= check\_box\_tag “company[market\_attributes][]”, market.id,  
@company.markets.include?(market) %\>  
\<%= label\_tag :market\_ids, market.name.upcase -%\>  
\<%= text\_field\_tag “emaildistro[#  
{market.id}]” %\>  

  
\<% end %\>  
  
\<% end %\>

controller:

company = Contactcompany.find(params[:company][:companyid])  
markets = params[:company][:market\_attributes] ||= []  
company.market\_ids = markets  
company.emails.each{|mail|  
distro = params[:emaildistro]["#{mail.market.id}"]  
mail.update\_attributes(:emaildistro =\> distro)  
}

Is there a way to retrieve the emails just like the checkboxes do when  
you pull up the view?
