title: AcitveRecord won't accepts_nested_attributes_for new associated records with nested existing records
body: <p>ActiveRecord doesn't seem to understand that, given a set of params for an existing record with nested attributes, it can create a new nested record that itself has a nested <em>existing</em> record.  (Relations tree: <code>Existing -&gt; New -&gt; Existing</code>)</p>
  
  <p>Is this a bug, or am I missing something?</p>
  
  <p>Let me show you a simple example.</p>
  
  <p>Here are my models:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :posts
    attr_accessible :name, :posts_attributes
    accepts_nested_attributes_for :posts
  end
  
  class Post &lt; ActiveRecord::Base
    belongs_to :group
    belongs_to :user
    attr_accessible :content, :title, :group_attributes
    accepts_nested_attributes_for :group
  end
  
  class Group &lt; ActiveRecord::Base
    has_many :posts
    attr_accessible :name
  end
  </code></pre>
  
  <p>I've made one record in each table, and related them accordingly, so each table has a record in it with an <code>id=1</code>--this is known.  Now, if I have an existing User, a new Post, and an existing Group, and try to update that record using <code>accepts_nested_attributes_for</code>, it doesn't like it:</p>
  
  <pre><code>1.9.3-p125 :044 &gt; params
  {
                    :id =&gt; 1,
                  :name =&gt; "Billy",
      :posts_attributes =&gt; [
          [0] {
                            :title =&gt; "Title",
                          :content =&gt; "Some magnificent content for you!",
              :group_attributes =&gt; {
                    :id =&gt; 1,
                  :name =&gt; "Group 1"
              }
          }
      ]
  }
  1.9.3-p125 :045 &gt; u
  #&lt;User:0x00000002f7f380&gt; {
              :id =&gt; 1,
            :name =&gt; "Billy",
      :created_at =&gt; Fri, 03 Aug 2012 20:21:37 UTC +00:00,
      :updated_at =&gt; Fri, 03 Aug 2012 20:21:37 UTC +00:00
  }
  1.9.3-p125 :046 &gt; u.update_attributes params
     (0.1ms)  begin transaction
     (0.1ms)  rollback transaction
  ActiveRecord::RecordNotFound: Couldn't find Group with ID=1 for Post with ID=
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/nested_attributes.rb:462:in `raise_nested_attributes_record_not_found'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/nested_attributes.rb:332:in `assign_nested_attributes_for_one_to_one_association'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/nested_attributes.rb:288:in `group_attributes='
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/attribute_assignment.rb:94:in `block in assign_attributes'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/attribute_assignment.rb:93:in `each'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/attribute_assignment.rb:93:in `assign_attributes'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/base.rb:498:in `initialize'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/reflection.rb:183:in `new'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/reflection.rb:183:in `build_association'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/associations/association.rb:233:in `build_record'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/associations/collection_association.rb:112:in `build'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/nested_attributes.rb:405:in `block in assign_nested_attributes_for_collection_association'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/nested_attributes.rb:400:in `each'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/nested_attributes.rb:400:in `assign_nested_attributes_for_collection_association'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/nested_attributes.rb:288:in `posts_attributes='
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/attribute_assignment.rb:78:in `each'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/persistence.rb:216:in `block in update_attributes'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/transactions.rb:208:in `transaction'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.7/lib/active_record/persistence.rb:215:in `update_attributes'
    from (irb):15
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/commands/console.rb:47:in `start'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/commands/console.rb:8:in `start'
    from /home/trevor/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/commands.rb:41:in `&lt;top (required)&gt;'
    from script/rails:6:in `require'
    from script/rails:6:in `&lt;main&gt;'1.9.3-p125 :047 &gt; 
  </code></pre>
  
  <p>It thinks it can't find a group (with a known ID), related to a new Post.
  It works when I remove the ID from the <code>group_attributes</code> (but it creates a new group record).
  It works when I give the <code>posts_attributes</code> an ID, and remove the id from the <code>group_attributes</code> (and again creates a new group).
  It also works when they all have IDs.</p>
  
  <p>The relationship is working:</p>
  
  <pre><code>1.9.3-p125 :059 &gt; p = Post.new( { group_attributes: { name: 'Testing' } } )
  #&lt;Post:0x00000004212380&gt; {
              :id =&gt; nil,
           :title =&gt; nil,
         :content =&gt; nil,
        :group_id =&gt; nil,
         :user_id =&gt; nil,
      :created_at =&gt; nil,
      :updated_at =&gt; nil
  }
  1.9.3-p125 :060 &gt; p.group
  [
      [0] #&lt;Group:0x00000004211868&gt; {
                  :id =&gt; nil,
                :name =&gt; "Testing",
          :created_at =&gt; nil,
          :updated_at =&gt; nil
      }
  ]
  </code></pre>
  
  <p>It also completely works when using <code>posts_attributes</code> and <code>group_attributes</code> during <code>User</code> creation, if all of the records are new.</p>
  
  <p>Shouldn't it work still in the first example?  ActiveRecord should be smart enough to figure this out...!</p>