title: has_many association with conditions on ActiveRecord
body: <p>I have this models: <code>Store</code> and <code>Address</code>.</p>
  
  <p>The second model <code>Address</code> I'm using this with other models and has some custom fields inside for different models.</p>
  
  <p>Yes like polymorphic but without the <code>varchar</code> field for Class, I'm using an integer. (optimization stuff)</p>
  
  <p>now on my <code>Store</code> model the association in set like this:</p>
  
  <pre><code>class Store &lt; ActiveRecord::Base
      has_many :addresses, :foreign_key =&gt; "parent_id", :conditions =&gt; ['parent_kind = ?', 2]
      accepts_nested_attributes_for :addresses
  end 
  </code></pre>
  
  <p>Now in my controller I do:</p>
  
  <p><code>@store.addresses.build</code></p>
  
  <p>And I can use <code>f.fields_for :addresses...</code> inside the form.</p>
  
  <p>The problem comes out when I submit the form and the data is saved to the database.</p>
  
  <p>The record in the <code>stores</code> table is saved, the record in <code>addresses</code> is saved with the <code>parent_id</code> of the store in place, but the <code>parent_kind</code> is in <code>0</code> which is the default value for that attribute on MySQL.</p>
  
  <p>My Quick fix was this:</p>
  
  <pre><code>@store = Store.new(params[:store])
      @store.addresses[0].parent_kind = 2
      if @store.save
      ....
  </code></pre>
  
  <p>But I know there must be another way.</p>
  
  <p>Anny suggestions?</p>
  
  <p>Thanks.</p>