<?xml version="1.0" encoding="UTF-8"?>
<ticket>
  <assigned-user-id type="integer">141</assigned-user-id>
  <attachments-count type="integer">4</attachments-count>
  <closed type="boolean">true</closed>
  <created-at type="datetime">2008-10-11T17:31:12+01:00</created-at>
  <creator-id type="integer">8406</creator-id>
  <milestone-due-on type="datetime" nil="true"></milestone-due-on>
  <milestone-id type="integer" nil="true"></milestone-id>
  <number type="integer">1202</number>
  <permalink>add-attributes-writer-method-for-an-association</permalink>
  <priority type="integer">19</priority>
  <project-id type="integer">8994</project-id>
  <raw-data type="binary" nil="true" encoding="base64"></raw-data>
  <state>committed</state>
  <tag>actionview activerecord enhancement patch</tag>
  <title>Add attributes writer method for an association.</title>
  <updated-at type="datetime">2009-12-03T14:45:27+00:00</updated-at>
  <user-id type="integer">22610</user-id>
  <user-name>Dusan Maliarik</user-name>
  <creator-name>Eloy Duran</creator-name>
  <assigned-user-name>Michael Koziarski</assigned-user-name>
  <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
  <original-body>This is the same problem :accessible tackled, but  with support for creation/updating/destroying associated records.

# What's in the patch? #
* AutosaveAssociation, which as the name implies automatically saves   
associations, not only on create as is the default.
* NestedParams, which is my take on this problem. It creates/updates/ 
destroys associations. It uses AutosaveAssociation. 
* FormBuilder with NestedParams support, which adds code to #fields_for for handling NestedParams enabled models.
* A few general patches not necessarily related to this new functionality. Namely:
  * Added mattr_accessor's for valid_keys_for_has_one_through_association &amp;  valid_keys_for_has_and_belongs_to_many_association.
    http://github.com/alloy/rails/commit/bdb4b34197544c473d369058c4c9609787f35ad0
  * Added a association instance get and set method, to dry up the 
associations code.
    http://github.com/alloy/rails/commit/e5dff966083030aeca9bb40890b92c04f9018357
    http://github.com/alloy/rails/commit/e4822d2a9d0aa047966335187ce78e40bb5488af
  * Remove MySQL BEGIN and COMMIT queries from $queries_executed before 
asserting number of queries.
    http://github.com/alloy/rails/commit/fbcfcec2fd320ff913b83aa619ee94c636199a10

# Examples #
_Taken from the docs._

When the &lt;tt&gt;:nested_params&lt;/tt&gt; option is enabled an extra attributes writer will be created for the association.
The attributes writer allows attributes of the associated model to be set directly with a hash.
This is handy for when, for instance, you have a form consisting of a parent and one or more child records.

All the associations that you enable &lt;tt&gt;:nested_params&lt;/tt&gt; on, will automatically have &lt;tt&gt;:autosave&lt;/tt&gt; turned on as well.

## Examples for a has_one / belongs_to association ##

@@@ ruby
class Member &lt; ActiveRecord::Base
  # This creates the following writer method: #avatar_attributes=
  has_one :avatar, :nested_params =&gt; true, :allow_destroy =&gt; true
end

# Adding an associated model:
params[:member] # =&gt; { 'name' =&gt; 'jack', 'avatar_attributes' =&gt; { 'name' =&gt; 'smiley' }}

member = Member.create(params[:member])
member.avatar.name # =&gt; 'smiley'

# Updating the associated model:
params # =&gt; { 'id' =&gt; '1', 'member' =&gt; { 'name' =&gt; 'joe', 'avatar_attributes' =&gt; { 'name' =&gt; 'sadly' }}}

member = Member.find(params[:id])
member.update_attributes params[:member]
member.avatar.name # =&gt; 'sadly'

# Destroy the associated model by adding the &lt;tt&gt;_destroy&lt;/tt&gt; attribute to the attributes hash.
# Turn it on with the :allow_destroy option (Turned off by default):
params[:member] # =&gt; { 'name' =&gt; 'joe', 'avatar_attributes' =&gt; { '_destroy' =&gt; '1' }}

member.update_attributes params[:member]
member.avatar # =&gt; nil
@@@

## Examples for a has_many / has_and_belongs_to_many association ##

@@@ ruby
class Member &lt; ActiveRecord::Base
  # This creates the following writer method: #posts_attributes=
  has_many :posts, :nested_params =&gt; true, :destroy_missing =&gt; true, :allow_destroy =&gt; true
end

# Creating associated models. Note that no records will be instantiated for any empty hashes:
params[:member] # =&gt; { 'name' =&gt; 'joe', 'posts_attributes' =&gt; {
  'new_12345' =&gt; { 'title' =&gt; 'first psot' },
  'new_54321' =&gt; { 'title' =&gt; 'other post' },
  'new_67890' =&gt; { 'title' =&gt; '' } # This one is empty and will not be instantiated.
}}

member = Member.create(params[:member])
member.posts.length # =&gt; 2
member.posts.first.title # =&gt; 'first psot'
member.posts.last.title # =&gt; 'other post'

# Updating the associated models:
params[:member] # =&gt; { 'name' =&gt; 'joe', 'posts_attributes' =&gt; {
  '1' =&gt; { 'title' =&gt; '[UPDATED] first psot' },
  '2' =&gt; { 'title' =&gt; '[UPDATED] other post' }
}}

member.update_attributes params[:member]
member.posts.first.title # =&gt; '[UPDATED] first psot'
member.posts.last.title # =&gt; '[UPDATED] other post'

# Destroy an associated model by leaving it out of the attributes hash.
# Turn it on with the :destroy_missing option (Turned off by default):
params[:member] # =&gt; { 'name' =&gt; 'joe', 'posts_attributes' =&gt; {
  '2' =&gt; { 'title' =&gt; '[UPDATED] other post is now the only post' }
}}

member.update_attributes params[:member]
member.posts.length # =&gt; 1
member.posts.first.title # =&gt; '[UPDATED] other post is now the only post'

# Or destroy an associated model by adding the &lt;tt&gt;_destroy&lt;/tt&gt; attribute to the attributes hash.
# Turn it on with the :allow_destroy option (Turned off by default):
params[:member] # =&gt; { 'name' =&gt; 'joe', 'posts_attributes' =&gt; {
  '2' =&gt; { '_destroy' =&gt; '1' }
}}

member.update_attributes params[:member]
member.posts.length # =&gt; 1
@@@

## Examples of FormBuilder#fields_for with a has_one / belongs_to association ##

@@@ ruby
  &lt;% form_for @person, :url =&gt; { :action =&gt; &quot;update&quot; } do |person_form| %&gt;
    ...
    &lt;% person_form.fields_for :address do |address_fields| %&gt;
      Street  : &lt;%= address_fields.text_field :street %&gt;
      Zip code: &lt;%= address_fields.text_field :zip_code %&gt;
    &lt;% end %&gt;
  &lt;% end %&gt;
@@@

## Examples of FormBuilder#fields_for with a has_many / has_and_belongs_to_many association ##

@@@ ruby
  &lt;% form_for @person, :url =&gt; { :action =&gt; &quot;update&quot; } do |person_form| %&gt;
    ...
    &lt;% person_form.fields_for :projects do |project_fields| %&gt;
      Name: &lt;%= project_fields.text_field :name %&gt;
    &lt;% end %&gt;
  &lt;% end %&gt;
@@@

Note: The block given to #fields_for will be repeated for each record and can optionally take the record instance as a second argument.

# Discussion #

* Most of the implementation has been discussed in this thread: http://groups.google.com/group/rubyonrails-core/browse_thread/thread/3c61e00916c365e5/ad1d4e40da933243
* I added the '_destroy' option as sugegested by Josh Susser, but I think that it will also require some extra support. Maybe in the form of a new FormBuilder method like #destroy, which would generate a checkbox for a record.
* I named the option :nested_params as in our original plugin, could also be named :accessible.
* Docs could probably be improved, I'd love feedback from people who read them.
* I have a fork of Ryan Bates's complex-form-examples in which I use these functionalities:
  http://github.com/alloy/complex-form-examples/tree/alloy-nested_params_merged_in_rails</original-body>
  <latest-body>This is the same problem :accessible tackled, but  with support for creation/updating/destroying associated records.

# What's in the patch? #
* AutosaveAssociation, which as the name implies automatically saves   
associations, not only on create as is the default.
* NestedParams, which is my take on this problem. It creates/updates/ 
destroys associations. It uses AutosaveAssociation. 
* FormBuilder with NestedParams support, which adds code to #fields_for for handling NestedParams enabled models.
* A few general patches not necessarily related to this new functionality. Namely:
  * Added mattr_accessor's for valid_keys_for_has_one_through_association &amp;  valid_keys_for_has_and_belongs_to_many_association.
    http://github.com/alloy/rails/commit/bdb4b34197544c473d369058c4c9609787f35ad0
  * Added a association instance get and set method, to dry up the 
associations code.
    http://github.com/alloy/rails/commit/e5dff966083030aeca9bb40890b92c04f9018357
    http://github.com/alloy/rails/commit/e4822d2a9d0aa047966335187ce78e40bb5488af
  * Remove MySQL BEGIN and COMMIT queries from $queries_executed before 
asserting number of queries.
    http://github.com/alloy/rails/commit/fbcfcec2fd320ff913b83aa619ee94c636199a10

# Examples #
_Taken from the docs._

When the &lt;tt&gt;:nested_params&lt;/tt&gt; option is enabled an extra attributes writer will be created for the association.
The attributes writer allows attributes of the associated model to be set directly with a hash.
This is handy for when, for instance, you have a form consisting of a parent and one or more child records.

All the associations that you enable &lt;tt&gt;:nested_params&lt;/tt&gt; on, will automatically have &lt;tt&gt;:autosave&lt;/tt&gt; turned on as well.

## Examples for a has_one / belongs_to association ##

@@@ ruby
class Member &lt; ActiveRecord::Base
  # This creates the following writer method: #avatar_attributes=
  has_one :avatar, :nested_params =&gt; true, :allow_destroy =&gt; true
end

# Adding an associated model:
params[:member] # =&gt; { 'name' =&gt; 'jack', 'avatar_attributes' =&gt; { 'name' =&gt; 'smiley' }}

member = Member.create(params[:member])
member.avatar.name # =&gt; 'smiley'

# Updating the associated model:
params # =&gt; { 'id' =&gt; '1', 'member' =&gt; { 'name' =&gt; 'joe', 'avatar_attributes' =&gt; { 'name' =&gt; 'sadly' }}}

member = Member.find(params[:id])
member.update_attributes params[:member]
member.avatar.name # =&gt; 'sadly'

# Destroy the associated model by adding the &lt;tt&gt;_destroy&lt;/tt&gt; attribute to the attributes hash.
# Turn it on with the :allow_destroy option (Turned off by default):
params[:member] # =&gt; { 'name' =&gt; 'joe', 'avatar_attributes' =&gt; { '_destroy' =&gt; '1' }}

member.update_attributes params[:member]
member.avatar # =&gt; nil
@@@

## Examples for a has_many / has_and_belongs_to_many association ##

@@@ ruby
class Member &lt; ActiveRecord::Base
  # This creates the following writer method: #posts_attributes=
  has_many :posts, :nested_params =&gt; true, :destroy_missing =&gt; true, :allow_destroy =&gt; true
end

# Creating associated models. Note that no records will be instantiated for any empty hashes:
params[:member] # =&gt; { 'name' =&gt; 'joe', 'posts_attributes' =&gt; {
  'new_12345' =&gt; { 'title' =&gt; 'first psot' },
  'new_54321' =&gt; { 'title' =&gt; 'other post' },
  'new_67890' =&gt; { 'title' =&gt; '' } # This one is empty and will not be instantiated.
}}

member = Member.create(params[:member])
member.posts.length # =&gt; 2
member.posts.first.title # =&gt; 'first psot'
member.posts.last.title # =&gt; 'other post'

# Updating the associated models:
params[:member] # =&gt; { 'name' =&gt; 'joe', 'posts_attributes' =&gt; {
  '1' =&gt; { 'title' =&gt; '[UPDATED] first psot' },
  '2' =&gt; { 'title' =&gt; '[UPDATED] other post' }
}}

member.update_attributes params[:member]
member.posts.first.title # =&gt; '[UPDATED] first psot'
member.posts.last.title # =&gt; '[UPDATED] other post'

# Destroy an associated model by leaving it out of the attributes hash.
# Turn it on with the :destroy_missing option (Turned off by default):
params[:member] # =&gt; { 'name' =&gt; 'joe', 'posts_attributes' =&gt; {
  '2' =&gt; { 'title' =&gt; '[UPDATED] other post is now the only post' }
}}

member.update_attributes params[:member]
member.posts.length # =&gt; 1
member.posts.first.title # =&gt; '[UPDATED] other post is now the only post'

# Or destroy an associated model by adding the &lt;tt&gt;_destroy&lt;/tt&gt; attribute to the attributes hash.
# Turn it on with the :allow_destroy option (Turned off by default):
params[:member] # =&gt; { 'name' =&gt; 'joe', 'posts_attributes' =&gt; {
  '2' =&gt; { '_destroy' =&gt; '1' }
}}

member.update_attributes params[:member]
member.posts.length # =&gt; 1
@@@

## Examples of FormBuilder#fields_for with a has_one / belongs_to association ##

@@@ ruby
  &lt;% form_for @person, :url =&gt; { :action =&gt; &quot;update&quot; } do |person_form| %&gt;
    ...
    &lt;% person_form.fields_for :address do |address_fields| %&gt;
      Street  : &lt;%= address_fields.text_field :street %&gt;
      Zip code: &lt;%= address_fields.text_field :zip_code %&gt;
    &lt;% end %&gt;
  &lt;% end %&gt;
@@@

## Examples of FormBuilder#fields_for with a has_many / has_and_belongs_to_many association ##

@@@ ruby
  &lt;% form_for @person, :url =&gt; { :action =&gt; &quot;update&quot; } do |person_form| %&gt;
    ...
    &lt;% person_form.fields_for :projects do |project_fields| %&gt;
      Name: &lt;%= project_fields.text_field :name %&gt;
    &lt;% end %&gt;
  &lt;% end %&gt;
@@@

Note: The block given to #fields_for will be repeated for each record and can optionally take the record instance as a second argument.

# Discussion #

* Most of the implementation has been discussed in this thread: http://groups.google.com/group/rubyonrails-core/browse_thread/thread/3c61e00916c365e5/ad1d4e40da933243
* I added the '_destroy' option as sugegested by Josh Susser, but I think that it will also require some extra support. Maybe in the form of a new FormBuilder method like #destroy, which would generate a checkbox for a record.
* I named the option :nested_params as in our original plugin, could also be named :accessible.
* Docs could probably be improved, I'd love feedback from people who read them.
* I have a fork of Ryan Bates's complex-form-examples in which I use these functionalities:
  http://github.com/alloy/complex-form-examples/tree/alloy-nested_params_merged_in_rails</latest-body>
  <original-body-html>&lt;div&gt;&lt;p&gt;This is the same problem :accessible tackled, but with support
for creation/updating/destroying associated records.&lt;/p&gt;
&lt;h1&gt;What's in the patch?&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;AutosaveAssociation, which as the name implies automatically
saves associations, not only on create as is the default.&lt;/li&gt;
&lt;li&gt;NestedParams, which is my take on this problem. It
creates/updates/ destroys associations. It uses
AutosaveAssociation.&lt;/li&gt;
&lt;li&gt;FormBuilder with NestedParams support, which adds code to
#fields_for for handling NestedParams enabled models.&lt;/li&gt;
&lt;li&gt;A few general patches not necessarily related to this new
functionality. Namely:
&lt;ul&gt;
&lt;li&gt;Added mattr_accessor's for
valid_keys_for_has_one_through_association &amp;amp;
valid_keys_for_has_and_belongs_to_many_association. &lt;a href=&quot;http://github.com/alloy/rails/commit/bdb4b34197544c473d369058c4c9609787f35ad0&quot;&gt;
http://github.com/alloy/rails/co...&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Added a association instance get and set method, to dry up the
associations code. &lt;a href=&quot;http://github.com/alloy/rails/commit/e5dff966083030aeca9bb40890b92c04f9018357&quot;&gt;
http://github.com/alloy/rails/co...&lt;/a&gt; &lt;a href=&quot;http://github.com/alloy/rails/commit/e4822d2a9d0aa047966335187ce78e40bb5488af&quot;&gt;
http://github.com/alloy/rails/co...&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Remove MySQL BEGIN and COMMIT queries from $queries_executed
before asserting number of queries. &lt;a href=&quot;http://github.com/alloy/rails/commit/fbcfcec2fd320ff913b83aa619ee94c636199a10&quot;&gt;
http://github.com/alloy/rails/co...&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;Examples&lt;/h1&gt;
&lt;p&gt;&lt;em&gt;Taken from the docs.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;When the :nested_params option is enabled an extra attributes
writer will be created for the association. The attributes writer
allows attributes of the associated model to be set directly with a
hash. This is handy for when, for instance, you have a form
consisting of a parent and one or more child records.&lt;/p&gt;
&lt;p&gt;All the associations that you enable :nested_params on, will
automatically have :autosave turned on as well.&lt;/p&gt;
&lt;h2&gt;Examples for a has_one / belongs_to association&lt;/h2&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
class Member &amp;lt; ActiveRecord::Base
  # This creates the following writer method: #avatar_attributes=
  has_one :avatar, :nested_params =&amp;gt; true, :allow_destroy =&amp;gt; true
end

# Adding an associated model:
params[:member] # =&amp;gt; { 'name' =&amp;gt; 'jack', 'avatar_attributes' =&amp;gt; { 'name' =&amp;gt; 'smiley' }}

member = Member.create(params[:member])
member.avatar.name # =&amp;gt; 'smiley'

# Updating the associated model:
params # =&amp;gt; { 'id' =&amp;gt; '1', 'member' =&amp;gt; { 'name' =&amp;gt; 'joe', 'avatar_attributes' =&amp;gt; { 'name' =&amp;gt; 'sadly' }}}

member = Member.find(params[:id])
member.update_attributes params[:member]
member.avatar.name # =&amp;gt; 'sadly'

# Destroy the associated model by adding the &amp;lt;tt&amp;gt;_destroy&amp;lt;/tt&amp;gt; attribute to the attributes hash.
# Turn it on with the :allow_destroy option (Turned off by default):
params[:member] # =&amp;gt; { 'name' =&amp;gt; 'joe', 'avatar_attributes' =&amp;gt; { '_destroy' =&amp;gt; '1' }}

member.update_attributes params[:member]
member.avatar # =&amp;gt; nil
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Examples for a has_many / has_and_belongs_to_many
association&lt;/h2&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
class Member &amp;lt; ActiveRecord::Base
  # This creates the following writer method: #posts_attributes=
  has_many :posts, :nested_params =&amp;gt; true, :destroy_missing =&amp;gt; true, :allow_destroy =&amp;gt; true
end

# Creating associated models. Note that no records will be instantiated for any empty hashes:
params[:member] # =&amp;gt; { 'name' =&amp;gt; 'joe', 'posts_attributes' =&amp;gt; {
  'new_12345' =&amp;gt; { 'title' =&amp;gt; 'first psot' },
  'new_54321' =&amp;gt; { 'title' =&amp;gt; 'other post' },
  'new_67890' =&amp;gt; { 'title' =&amp;gt; '' } # This one is empty and will not be instantiated.
}}

member = Member.create(params[:member])
member.posts.length # =&amp;gt; 2
member.posts.first.title # =&amp;gt; 'first psot'
member.posts.last.title # =&amp;gt; 'other post'

# Updating the associated models:
params[:member] # =&amp;gt; { 'name' =&amp;gt; 'joe', 'posts_attributes' =&amp;gt; {
  '1' =&amp;gt; { 'title' =&amp;gt; '[UPDATED] first psot' },
  '2' =&amp;gt; { 'title' =&amp;gt; '[UPDATED] other post' }
}}

member.update_attributes params[:member]
member.posts.first.title # =&amp;gt; '[UPDATED] first psot'
member.posts.last.title # =&amp;gt; '[UPDATED] other post'

# Destroy an associated model by leaving it out of the attributes hash.
# Turn it on with the :destroy_missing option (Turned off by default):
params[:member] # =&amp;gt; { 'name' =&amp;gt; 'joe', 'posts_attributes' =&amp;gt; {
  '2' =&amp;gt; { 'title' =&amp;gt; '[UPDATED] other post is now the only post' }
}}

member.update_attributes params[:member]
member.posts.length # =&amp;gt; 1
member.posts.first.title # =&amp;gt; '[UPDATED] other post is now the only post'

# Or destroy an associated model by adding the &amp;lt;tt&amp;gt;_destroy&amp;lt;/tt&amp;gt; attribute to the attributes hash.
# Turn it on with the :allow_destroy option (Turned off by default):
params[:member] # =&amp;gt; { 'name' =&amp;gt; 'joe', 'posts_attributes' =&amp;gt; {
  '2' =&amp;gt; { '_destroy' =&amp;gt; '1' }
}}

member.update_attributes params[:member]
member.posts.length # =&amp;gt; 1
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Examples of FormBuilder#fields_for with a has_one / belongs_to
association&lt;/h2&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
  &amp;lt;% form_for @person, :url =&amp;gt; { :action =&amp;gt; &amp;quot;update&amp;quot; } do |person_form| %&amp;gt;
    ...
    &amp;lt;% person_form.fields_for :address do |address_fields| %&amp;gt;
      Street  : &amp;lt;%= address_fields.text_field :street %&amp;gt;
      Zip code: &amp;lt;%= address_fields.text_field :zip_code %&amp;gt;
    &amp;lt;% end %&amp;gt;
  &amp;lt;% end %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Examples of FormBuilder#fields_for with a has_many /
has_and_belongs_to_many association&lt;/h2&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
  &amp;lt;% form_for @person, :url =&amp;gt; { :action =&amp;gt; &amp;quot;update&amp;quot; } do |person_form| %&amp;gt;
    ...
    &amp;lt;% person_form.fields_for :projects do |project_fields| %&amp;gt;
      Name: &amp;lt;%= project_fields.text_field :name %&amp;gt;
    &amp;lt;% end %&amp;gt;
  &amp;lt;% end %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note: The block given to #fields_for will be repeated for each
record and can optionally take the record instance as a second
argument.&lt;/p&gt;
&lt;h1&gt;Discussion&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Most of the implementation has been discussed in this thread:
&lt;a href=&quot;http://groups.google.com/group/rubyonrails-core/browse_thread/thread/3c61e00916c365e5/ad1d4e40da933243&quot;&gt;
http://groups.google.com/group/r...&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;I added the '_destroy' option as sugegested by Josh Susser, but
I think that it will also require some extra support. Maybe in the
form of a new FormBuilder method like #destroy, which would
generate a checkbox for a record.&lt;/li&gt;
&lt;li&gt;I named the option :nested_params as in our original plugin,
could also be named :accessible.&lt;/li&gt;
&lt;li&gt;Docs could probably be improved, I'd love feedback from people
who read them.&lt;/li&gt;
&lt;li&gt;I have a fork of Ryan Bates's complex-form-examples in which I
use these functionalities: &lt;a href=&quot;http://github.com/alloy/complex-form-examples/tree/alloy-nested_params_merged_in_rails&quot;&gt;
http://github.com/alloy/complex-...&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;</original-body-html>
  <versions type="array">
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>This is the same problem :accessible tackled, but with support for creation/updating/destroying associated records.

_Note: I have updated the patches for edge and normalized them again. I removed the old documentation here because it just clobbers the whole page._

## What's in the patch? ##
* AutosaveAssociation, which as the name implies automatically saves   
associations, not only on create as is the default.
* NestedAttributes, which is my take on this problem. It creates/updates/ 
destroys associations. (It uses AutosaveAssociation.)
* FormBuilder with NestedAttributes support, which adds code to #fields_for for handling, amongst others, NestedAttributes models.

## Examples ##
Please see the documentation of AutosaveAssociation, NestedAttributes, and FormBuilder#fields_for.
Also expect to see some more elaborate explanation on a well known blog in the near future. I will add the url here once that has been done.

You can also checkout my fork of Ryan Bates's complex-form-examples which uses it:
http://github.com/alloy/complex-form-examples/commits/nested_attributes

## Patches ##
The AutosaveAssociation and NestedAttributes patches rely on the following patches:

* Accessor methods for association instances. #1728
* Remove transaction queries from assert_queries count. #1732

After applying those two you can apply the AutosaveAssociation patch and finally the NestedAttributes patch.</body>
      <body-html>&lt;div&gt;&lt;p&gt;This is the same problem :accessible tackled, but with support
for creation/updating/destroying associated records.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: I have updated the patches for edge and normalized
them again. I removed the old documentation here because it just
clobbers the whole page.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;What's in the patch?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;AutosaveAssociation, which as the name implies automatically
saves&lt;br&gt;
associations, not only on create as is the default.&lt;/li&gt;
&lt;li&gt;NestedAttributes, which is my take on this problem. It
creates/updates/ destroys associations. (It uses
AutosaveAssociation.)&lt;/li&gt;
&lt;li&gt;FormBuilder with NestedAttributes support, which adds code to
#fields_for for handling, amongst others, NestedAttributes
models.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Examples&lt;/h2&gt;
&lt;p&gt;Please see the documentation of AutosaveAssociation,
NestedAttributes, and FormBuilder#fields_for. Also expect to see
some more elaborate explanation on a well known blog in the near
future. I will add the url here once that has been done.&lt;/p&gt;
&lt;p&gt;You can also checkout my fork of Ryan Bates's
complex-form-examples which uses it: &lt;a href=&quot;http://github.com/alloy/complex-form-examples/commits/nested_attributes&quot;&gt;
http://github.com/alloy/complex-...&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Patches&lt;/h2&gt;
&lt;p&gt;The AutosaveAssociation and NestedAttributes patches rely on the
following patches:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Accessor methods for association instances. &lt;a href=&quot;/projects/8994/tickets/1728&quot; title=&quot;Ticket #1728&quot;&gt;#1728&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Remove transaction queries from assert_queries count. &lt;a href=&quot;/projects/8994/tickets/1732&quot; title=&quot;Ticket #1732&quot;&gt;#1732&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;After applying those two you can apply the AutosaveAssociation
patch and finally the NestedAttributes patch.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-10-11T17:31:12+01:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-21T15:56:04+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>In the following example:

  # Creating associated models. Note that no records will be instantiated for any empty hashes:
  params[:member] # =&gt; { 'name' =&gt; 'joe', 'posts_attributes' =&gt; {
    'new_12345' =&gt; { 'title' =&gt; 'first psot' },
    'new_54321' =&gt; { 'title' =&gt; 'other post' },
    'new_67890' =&gt; { 'title' =&gt; '' } # This one is empty and will not be instantiated.
  }}
, what significance does `new_12345` and the other keys have?

Would it make more sense to have the `posts_attributes` be an array of hashes instead?</body>
      <body-html>&lt;div&gt;&lt;p&gt;In the following example:&lt;/p&gt;
&lt;p&gt;# Creating associated models. Note that no records will be
instantiated for any empty hashes: params[:member] # =&amp;gt; { 'name'
=&amp;gt; 'joe', 'posts_attributes' =&amp;gt; {&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;'new_12345' =&amp;gt; { 'title' =&amp;gt; 'first psot' },
'new_54321' =&amp;gt; { 'title' =&amp;gt; 'other post' },
'new_67890' =&amp;gt; { 'title' =&amp;gt; '' } # This one is empty and will not be instantiated.
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;}} , what significance does &lt;code&gt;new_12345&lt;/code&gt; and the other
keys have?&lt;/p&gt;
&lt;p&gt;Would it make more sense to have the
&lt;code&gt;posts_attributes&lt;/code&gt; be an array of hashes instead?&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-10-11T20:15:12+01:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-10-11T20:15:14+01:00</updated-at>
      <user-id type="integer">17949</user-id>
      <user-name>Daniel Schierbeck</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>The last example should of course have been:

    # Creating associated models. Note that no records will be instantiated for any empty hashes:
    params[:member] # =&gt; { 'name' =&gt; 'joe', 'posts_attributes' =&gt; {
      'new_12345' =&gt; { 'title' =&gt; 'first psot' },
      'new_54321' =&gt; { 'title' =&gt; 'other post' },
      'new_67890' =&gt; { 'title' =&gt; '' } # This one is empty and will not be instantiated.
    }}</body>
      <body-html>&lt;div&gt;&lt;p&gt;The last example should of course have been:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;# Creating associated models. Note that no records will be instantiated for any empty hashes:
params[:member] # =&amp;gt; { 'name' =&amp;gt; 'joe', 'posts_attributes' =&amp;gt; {
  'new_12345' =&amp;gt; { 'title' =&amp;gt; 'first psot' },
  'new_54321' =&amp;gt; { 'title' =&amp;gt; 'other post' },
  'new_67890' =&amp;gt; { 'title' =&amp;gt; '' } # This one is empty and will not be instantiated.
}}
&lt;/code&gt;
&lt;/pre&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-10-11T20:16:23+01:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-10-11T20:16:25+01:00</updated-at>
      <user-id type="integer">17949</user-id>
      <user-name>Daniel Schierbeck</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>An array of hashes for new records is also supported.

The &#8220;new_123&#8221; keys however, are so that you can mix existing records with new ones. These keys are generated by the modified FormBuilder#fields_for for new records, or you can create them yourself if your using an API for instance.</body>
      <body-html>&lt;div&gt;&lt;p&gt;An array of hashes for new records is also supported.&lt;/p&gt;
&lt;p&gt;The &amp;#8220;new_123&amp;#8221; keys however, are so that you can mix
existing records with new ones. These keys are generated by the
modified FormBuilder#fields_for for new records, or you can create
them yourself if your using an API for instance.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-10-12T12:43:29+01:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-10-12T12:43:33+01:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>I should have added that a hash is what gets created by the parameter parser if you have records with an id and an array is what gets created for a collection of records without an id.
So for this to work, in a scenario where you have mixed new and existing records, it should support a hash and not an array and thus should have at least some sort of index key for each record.</body>
      <body-html>&lt;div&gt;&lt;p&gt;I should have added that a hash is what gets created by the
parameter parser if you have records with an id and an array is
what gets created for a collection of records without an id. So for
this to work, in a scenario where you have mixed new and existing
records, it should support a hash and not an array and thus should
have at least some sort of index key for each record.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-10-12T12:51:54+01:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-10-12T12:51:54+01:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>Added a new patch with:
- better NestedParams docs by Manfred Stienstra.
- #acts_like_hash? for Hash and ActiveSupport::OrderedHash
- updated to work with current edge Rails (09c1718).</body>
      <body-html>&lt;div&gt;&lt;p&gt;Added a new patch with: - better NestedParams docs by Manfred
Stienstra. - #acts_like_hash? for Hash and
ActiveSupport::OrderedHash - updated to work with current edge
Rails (09c1718).&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-10-15T11:14:52+01:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-10-15T11:14:55+01:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>This is the best and most complete approach to that issue that I've seen to far.

+1 from my side, but I don't think it should make it into 2.2 as you can never be sure it doesn't break something.

That said, do you think you could make this a heavily monkey-patching plugin or gem for the time being?
I would love to use it for my next project, together with considerably stable 2.2.</body>
      <body-html>&lt;div&gt;&lt;p&gt;This is the best and most complete approach to that issue that
I've seen to far.&lt;/p&gt;
&lt;p&gt;+1 from my side, but I don't think it should make it into 2.2 as
you can never be sure it doesn't break something.&lt;/p&gt;
&lt;p&gt;That said, do you think you could make this a heavily
monkey-patching plugin or gem for the time being? I would love to
use it for my next project, together with considerably stable
2.2.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-10-16T16:25:47+01:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-10-16T16:25:53+01:00</updated-at>
      <user-id type="integer">19954</user-id>
      <user-name>Pascal Ehlert</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>@Pascal: If I find some time I'll see about back porting into the plugin.

I myself think it would need more testing, so 2.2 is probably too close already.</body>
      <body-html>&lt;div&gt;&lt;p&gt;@Pascal: If I find some time I'll see about back porting into
the plugin.&lt;/p&gt;
&lt;p&gt;I myself think it would need more testing, so 2.2 is probably
too close already.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-10-16T17:24:25+01:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-10-16T17:24:29+01:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>looks like a winner to me
+1</body>
      <body-html>&lt;div&gt;&lt;p&gt;looks like a winner to me +1&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-10-21T05:40:06+01:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-10-21T05:40:08+01:00</updated-at>
      <user-id type="integer">11268</user-id>
      <user-name>linoj</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>I like this patch a lot, but have a few comments.

The whole autosave thing seems flawed, as it's currently implemented. Why save all associations all the time? We have changed? and friends to help us decide when to save. Saving associations all the time will emit a lot of queries. But, it's possible that I missed something, since I didn't read every line.

I hate the name. params is an action_controller term. They should have some other name in active_record, since they're not tied to external params. Perhaps :attributes =&gt; true ?

Lastly, I'm sorry to say that I don't feel that the code quality is really there. I find the methods very long, winding and difficult to read. My big problem with this patch is that I've been staring at it for quite a while, and I still don't feel like I really understand how it works.

I really think that it would be nice to refactor this code in to a class that handles all the logic around saving and validating collections of active_record objects. I have been working on something similar for my active_presenter plugin, but haven't got anything quite finished yet. It would be a lot more flexible that way, because you could use it for more than just associations (i.e. collections of top level objects in one form). It would also provide better encapsulation and testability.</body>
      <body-html>&lt;div&gt;&lt;p&gt;I like this patch a lot, but have a few comments.&lt;/p&gt;
&lt;p&gt;The whole autosave thing seems flawed, as it's currently
implemented. Why save all associations all the time? We have
changed? and friends to help us decide when to save. Saving
associations all the time will emit a lot of queries. But, it's
possible that I missed something, since I didn't read every
line.&lt;/p&gt;
&lt;p&gt;I hate the name. params is an action_controller term. They
should have some other name in active_record, since they're not
tied to external params. Perhaps :attributes =&amp;gt; true ?&lt;/p&gt;
&lt;p&gt;Lastly, I'm sorry to say that I don't feel that the code quality
is really there. I find the methods very long, winding and
difficult to read. My big problem with this patch is that I've been
staring at it for quite a while, and I still don't feel like I
really understand how it works.&lt;/p&gt;
&lt;p&gt;I really think that it would be nice to refactor this code in to
a class that handles all the logic around saving and validating
collections of active_record objects. I have been working on
something similar for my active_presenter plugin, but haven't got
anything quite finished yet. It would be a lot more flexible that
way, because you could use it for more than just associations (i.e.
collections of top level objects in one form). It would also
provide better encapsulation and testability.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-11-22T16:49:36+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-11-22T16:49:38+00:00</updated-at>
      <user-id type="integer">9497</user-id>
      <user-name>James</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>&#8220;The whole autosave thing seems flawed, as it's currently implemented. Why save all associations all the time? We have changed? and friends to help us decide when to save. Saving associations all the time will emit a lot of queries. But, it's possible that I missed something, since I didn't read every line.&#8221;

ActiveRecord::Base#save shouldn't actually perform any queries if the record is not changed? So there's no need to duplicate that code. I'll double check though if it really doesn't, when I update the patch one of these days.

&#8220;I hate the name. params is an action_controller term. They should have some other name in active_record, since they're not tied to external params. Perhaps :attributes =&gt; true ?&#8221;

I agree. However just :attributes doesn't tell me enough. How about :nested_attributes ?

&#8220;Lastly, I'm sorry to say that I don't feel that the code quality is really there. I find the methods very long, winding and difficult to read. My big problem with this patch is that I've been staring at it for quite a while, and I still don't feel like I really understand how it works.&#8221;

The long methods were meant as being descriptive.
Please tell me which methods and why you find they are hard to grok.

&#8220;I really think that it would be nice to refactor this code in to a class that handles all the logic around saving and validating collections of active_record objects. I have been working on something similar for my active_presenter plugin, but haven't got anything quite finished yet. It would be a lot more flexible that way, because you could use it for more than just associations (i.e. collections of top level objects in one form). It would also provide better encapsulation and testability.&#8221;

I haven't had a need for that in the application that we used it in.

Thanks,
Eloy</body>
      <body-html>&lt;div&gt;&lt;p&gt;&amp;#8220;The whole autosave thing seems flawed, as it's currently
implemented. Why save all associations all the time? We have
changed? and friends to help us decide when to save. Saving
associations all the time will emit a lot of queries. But, it's
possible that I missed something, since I didn't read every
line.&amp;#8221;&lt;/p&gt;
&lt;p&gt;ActiveRecord::Base#save shouldn't actually perform any queries
if the record is not changed? So there's no need to duplicate that
code. I'll double check though if it really doesn't, when I update
the patch one of these days.&lt;/p&gt;
&lt;p&gt;&amp;#8220;I hate the name. params is an action_controller term.
They should have some other name in active_record, since they're
not tied to external params. Perhaps :attributes =&amp;gt; true
?&amp;#8221;&lt;/p&gt;
&lt;p&gt;I agree. However just :attributes doesn't tell me enough. How
about :nested_attributes ?&lt;/p&gt;
&lt;p&gt;&amp;#8220;Lastly, I'm sorry to say that I don't feel that the code
quality is really there. I find the methods very long, winding and
difficult to read. My big problem with this patch is that I've been
staring at it for quite a while, and I still don't feel like I
really understand how it works.&amp;#8221;&lt;/p&gt;
&lt;p&gt;The long methods were meant as being descriptive. Please tell me
which methods and why you find they are hard to grok.&lt;/p&gt;
&lt;p&gt;&amp;#8220;I really think that it would be nice to refactor this
code in to a class that handles all the logic around saving and
validating collections of active_record objects. I have been
working on something similar for my active_presenter plugin, but
haven't got anything quite finished yet. It would be a lot more
flexible that way, because you could use it for more than just
associations (i.e. collections of top level objects in one form).
It would also provide better encapsulation and
testability.&amp;#8221;&lt;/p&gt;
&lt;p&gt;I haven't had a need for that in the application that we used it
in.&lt;/p&gt;
&lt;p&gt;Thanks, Eloy&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-11-22T18:03:27+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-11-22T18:03:31+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>They're not nested in the context of the declaration though. You don't say has_many :nested_class_name =&gt;... You say :class_name. The fact that it's has_many implies that it's nested.

One example of code that I find difficult to grok is define_nested_params_writer_for_collection_association. It goes up to about 12 levels of indentation with many nested conditionals and other statements. The method is about 30 lines long, which makes it easy to lose context as you read through it. Nested conditionals like that are ugly, and there's really no reason to use them in ruby. There are other examples in this set of patches.

I don't understand your point about not needing that in your application. You don't need well factored, properly encapsulated code? You may not need the feature of editing many top-level models at once, but adding all this code to one place blurs responsibilities, and means that extracting it to do anything else later on is going to be impossible.

I'm currently working on a refactoring of action_pack, and let me tell you, the lack of encapsulation is making it VERY hard. ActionController::Base has about a million responsibilities that are all tangled up in eachother. That makes it really bloody hard to refactor. Really, really bloody hard.</body>
      <body-html>&lt;div&gt;&lt;p&gt;They're not nested in the context of the declaration though. You
don't say has_many :nested_class_name =&amp;gt;... You say :class_name.
The fact that it's has_many implies that it's nested.&lt;/p&gt;
&lt;p&gt;One example of code that I find difficult to grok is
define_nested_params_writer_for_collection_association. It goes up
to about 12 levels of indentation with many nested conditionals and
other statements. The method is about 30 lines long, which makes it
easy to lose context as you read through it. Nested conditionals
like that are ugly, and there's really no reason to use them in
ruby. There are other examples in this set of patches.&lt;/p&gt;
&lt;p&gt;I don't understand your point about not needing that in your
application. You don't need well factored, properly encapsulated
code? You may not need the feature of editing many top-level models
at once, but adding all this code to one place blurs
responsibilities, and means that extracting it to do anything else
later on is going to be impossible.&lt;/p&gt;
&lt;p&gt;I'm currently working on a refactoring of action_pack, and let
me tell you, the lack of encapsulation is making it VERY hard.
ActionController::Base has about a million responsibilities that
are all tangled up in eachother. That makes it really bloody hard
to refactor. Really, really bloody hard.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-11-22T18:20:44+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-11-22T18:20:45+00:00</updated-at>
      <user-id type="integer">9497</user-id>
      <user-name>James</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>&#8220;They're not nested in the context of the declaration though. You don't say has_many :nested_class_name =&gt;... You say :class_name. The fact that it's has_many implies that it's nested.&#8221;

:attributes is still too abstract for me.

&#8220;I don't understand your point about not needing that in your application. You don't need well factored, properly encapsulated code? You may not need the feature of editing many top-level models at once, but adding all this code to one place blurs responsibilities, and means that extracting it to do anything else later on is going to be impossible.&#8221;

Obviously the latter.</body>
      <body-html>&lt;div&gt;&lt;p&gt;&amp;#8220;They're not nested in the context of the declaration
though. You don't say has_many :nested_class_name =&amp;gt;... You say
:class_name. The fact that it's has_many implies that it's
nested.&amp;#8221;&lt;/p&gt;
&lt;p&gt;:attributes is still too abstract for me.&lt;/p&gt;
&lt;p&gt;&amp;#8220;I don't understand your point about not needing that in
your application. You don't need well factored, properly
encapsulated code? You may not need the feature of editing many
top-level models at once, but adding all this code to one place
blurs responsibilities, and means that extracting it to do anything
else later on is going to be impossible.&amp;#8221;&lt;/p&gt;
&lt;p&gt;Obviously the latter.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-11-23T12:26:15+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-11-23T12:26:21+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Uploaded an updated patch for current HEAD.

I changed the option from :nested_params to :accept_nested_attributes, which should more clearly express it's intent.
Also the big method in ActiveRecord::NestedAttributes has been split up into smaller methods.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Uploaded an updated patch for current HEAD.&lt;/p&gt;
&lt;p&gt;I changed the option from :nested_params to
:accept_nested_attributes, which should more clearly express it's
intent. Also the big method in ActiveRecord::NestedAttributes has
been split up into smaller methods.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-12-03T20:19:07+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-12-03T20:19:13+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body></body>
      <body-html></body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-12-04T11:04:03+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- 
:milestone: 9903
:assigned_user: 
</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-12-04T11:04:07+00:00</updated-at>
      <user-id type="integer">1366</user-id>
      <user-name>Pratik</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Could you rebase the patch down to one changeset, it's pretty hard to follow when spread over several changes.

Also, the use of alias_method_chain isn't needed here. You should be able to make those changes inline.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Could you rebase the patch down to one changeset, it's pretty
hard to follow when spread over several changes.&lt;/p&gt;
&lt;p&gt;Also, the use of alias_method_chain isn't needed here. You
should be able to make those changes inline.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-12-10T19:18:53+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-12-10T19:18:58+00:00</updated-at>
      <user-id type="integer">141</user-id>
      <user-name>Michael Koziarski</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>I created a flattened patch, which is updated for edge again. The changes to OrderedHash caused some breakage, so this patch depends on the patch in ticket #1559.</body>
      <body-html>&lt;div&gt;&lt;p&gt;I created a flattened patch, which is updated for edge again.
The changes to OrderedHash caused some breakage, so this patch
depends on the patch in ticket &lt;a href=&quot;/projects/8994/tickets/1559&quot; title=&quot;Ticket #1559&quot;&gt;#1559&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-12-11T13:48:51+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-12-11T13:48:53+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Sorry that I missed this before rolling yet another solution!

Some thoughts on the patch:

* Form builders are nice! There's something I'm missing in my plugin.
* I'm not a fan of the new_1234 hash keys. Are those actually meaningful? I didn't see if they're parsed in the code, but they're still used in the examples and tests and that's a bit confusing.
* Your patch ignores new records that are &quot;empty&quot;. That's how I did this back in ActiveScaffold, and it doesn't work in practice. You will run into problems with form elements that always have values like date selectors, radio buttons, or dropdowns.
* I think you're supporting too many different ways of doing things. We should be opinionated, right? Let's not support deleting records with missing rows. That may work sometimes, but not always, whereas the :_destroy key does work always (and can solve the problem with empty new records, too).
* I don't like :autosave as an option. It's too much configuration for me. I would rather have an intelligent autosave that simply worked as expected.
* The :allow_destroy, :destroy_missing, and :accept_nested_attributes options don't feel like association configuration. That is, they don't relate to how the association is set up. Instead they relate to how the association responds to mass assignment from a form. It just feels ... slightly off. I'd rather keep the association setup all database-related with foreign keys, class names, conditions, etc.

Please feel free to steal any ideas from my new plugin at http://github.com/cainlevy/nested_assignment/tree/master. An example implementation is available at http://github.com/cainlevy/complex-form-examples/tree/cainlevy.

-Lance</body>
      <body-html>&lt;div&gt;&lt;p&gt;Sorry that I missed this before rolling yet another
solution!&lt;/p&gt;
&lt;p&gt;Some thoughts on the patch:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Form builders are nice! There's something I'm missing in my
plugin.&lt;/li&gt;
&lt;li&gt;I'm not a fan of the new_1234 hash keys. Are those actually
meaningful? I didn't see if they're parsed in the code, but they're
still used in the examples and tests and that's a bit
confusing.&lt;/li&gt;
&lt;li&gt;Your patch ignores new records that are &quot;empty&quot;. That's how I
did this back in ActiveScaffold, and it doesn't work in practice.
You will run into problems with form elements that always have
values like date selectors, radio buttons, or dropdowns.&lt;/li&gt;
&lt;li&gt;I think you're supporting too many different ways of doing
things. We should be opinionated, right? Let's not support deleting
records with missing rows. That may work sometimes, but not always,
whereas the :_destroy key does work always (and can solve the
problem with empty new records, too).&lt;/li&gt;
&lt;li&gt;I don't like :autosave as an option. It's too much
configuration for me. I would rather have an intelligent autosave
that simply worked as expected.&lt;/li&gt;
&lt;li&gt;The :allow_destroy, :destroy_missing, and
:accept_nested_attributes options don't feel like association
configuration. That is, they don't relate to how the association is
set up. Instead they relate to how the association responds to mass
assignment from a form. It just feels ... slightly off. I'd rather
keep the association setup all database-related with foreign keys,
class names, conditions, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Please feel free to steal any ideas from my new plugin at
&lt;a href=&quot;http://github.com/cainlevy/nested_assignment/tree/master&quot;&gt;http://github.com/cainlevy/neste...&lt;/a&gt;.
An example implementation is available at &lt;a href=&quot;http://github.com/cainlevy/complex-form-examples/tree/cainlevy.%3C/p&quot;&gt;
http://github.com/cainlevy/compl...&lt;/a&gt;&amp;gt;&lt;/p&gt;
&lt;p&gt;-Lance&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-12-14T22:22:06+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-12-14T22:22:10+00:00</updated-at>
      <user-id type="integer">8964</user-id>
      <user-name>cainlevy</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>When this will land in 2.3 ?</body>
      <body-html>&lt;div&gt;&lt;p&gt;When this will land in 2.3 ?&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-12-17T11:33:09+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-12-17T11:33:13+00:00</updated-at>
      <user-id type="integer">11785</user-id>
      <user-name>Pawe&#322; Kondzior</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>I will first update the patch once more with some of the feedback from Lance, on this ticket but also by email. So _at least_ it won't be until I've had time for that, which will probably be in this/next week.</body>
      <body-html>&lt;div&gt;&lt;p&gt;I will first update the patch once more with some of the
feedback from Lance, on this ticket but also by email. So &lt;em&gt;at
least&lt;/em&gt; it won't be until I've had time for that, which will
probably be in this/next week.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-12-17T12:24:31+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-12-17T12:24:36+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>I'm also travelling for a week or two but intend to take a closer look
when I get back on deck.

Things will slip a bit over the holidays, but we'll get there :)</body>
      <body-html>&lt;div&gt;&lt;p&gt;I'm also travelling for a week or two but intend to take a
closer look when I get back on deck.&lt;/p&gt;
&lt;p&gt;Things will slip a bit over the holidays, but we'll get there
:)&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-12-17T12:29:28+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-12-17T12:29:28+00:00</updated-at>
      <user-id type="integer">141</user-id>
      <user-name>Michael Koziarski</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>This is Model#nested_changes proposal of implementation.

changes format for one_to_one:
http://pastie.org/341324

for collections there is only one difference, they are all in [] instead of directly hash:
{ &quot;reflaction&quot; =&gt; { :created =&gt; [{...}, {...}, ...] }

There is no tests in this patch, and no nested_changes.clear after save.

What do you thnik about this ? If there is place for such implementation here i can do the rest of issues that need to be solved here.


BTW. there is a bug in assign_to_or_destroy_nested_attributes_records, it should throw NoRecord or similar exception for id that doesn't exsists. Now it throws nil.attributes= exception.</body>
      <body-html>&lt;div&gt;&lt;p&gt;This is Model#nested_changes proposal of implementation.&lt;/p&gt;
&lt;p&gt;changes format for one_to_one: &lt;a href=&quot;http://pastie.org/341324&quot;&gt;http://pastie.org/341324&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;for collections there is only one difference, they are all in []
instead of directly hash: { &quot;reflaction&quot; =&amp;gt; { :created =&amp;gt;
[{...}, {...}, ...] }&lt;/p&gt;
&lt;p&gt;There is no tests in this patch, and no nested_changes.clear
after save.&lt;/p&gt;
&lt;p&gt;What do you thnik about this ? If there is place for such
implementation here i can do the rest of issues that need to be
solved here.&lt;/p&gt;
&lt;p&gt;BTW. there is a bug in
assign_to_or_destroy_nested_attributes_records, it should throw
NoRecord or similar exception for id that doesn't exsists. Now it
throws nil.attributes= exception.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-12-17T16:05:51+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2008-12-17T16:05:55+00:00</updated-at>
      <user-id type="integer">11785</user-id>
      <user-name>Pawe&#322; Kondzior</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body>*bump*
Any progress on this? I'm really curious to see this functionality in the core as none of the available plugins can keep up with the proposed patches.</body>
      <body-html>&lt;div&gt;&lt;p&gt;&lt;em&gt;bump&lt;/em&gt; Any progress on this? I'm really curious to see
this functionality in the core as none of the available plugins can
keep up with the proposed patches.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-09T14:23:51+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-09T14:23:56+00:00</updated-at>
      <user-id type="integer">19954</user-id>
      <user-name>Pascal Ehlert</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body>It's still progressing, I just started discussing some stuff with Michael.
So expect a new and hopefully final patch.</body>
      <body-html>&lt;div&gt;&lt;p&gt;It's still progressing, I just started discussing some stuff
with Michael. So expect a new and hopefully final patch.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-09T15:14:29+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-09T15:14:33+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body>Excellent, I'm glad to hear that.
I just thought it might not get the attention it deserves ;-)

Thanks a lot for your hard work guys.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Excellent, I'm glad to hear that. I just thought it might not
get the attention it deserves ;-)&lt;/p&gt;
&lt;p&gt;Thanks a lot for your hard work guys.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-09T15:26:29+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-09T15:26:35+00:00</updated-at>
      <user-id type="integer">19954</user-id>
      <user-name>Pascal Ehlert</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body>I know I'm late to the party, but I'd like to test and help contribute to the next patch if it's okay. Eloy, do you think we can communicate over email? ryan AT railscasts DOT com.</body>
      <body-html>&lt;div&gt;&lt;p&gt;I know I'm late to the party, but I'd like to test and help
contribute to the next patch if it's okay. Eloy, do you think we
can communicate over email? ryan AT railscasts DOT com.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-09T16:40:39+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-09T16:40:44+00:00</updated-at>
      <user-id type="integer">5701</user-id>
      <user-name>Ryan Bates</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body>+1</body>
      <body-html>&lt;div&gt;&lt;p&gt;+1&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-11T11:36:42+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-11T18:19:03+00:00</updated-at>
      <user-id type="integer">14415</user-id>
      <user-name>J&#233;r&#244;me</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body>+1</body>
      <body-html>&lt;div&gt;&lt;p&gt;+1&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-12T09:05:11+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-12T09:05:12+00:00</updated-at>
      <user-id type="integer">18156</user-id>
      <user-name>Nicolas Blanco</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body>New AutosaveAssociation patch, updated for edge and normalized into 1 diff.</body>
      <body-html>&lt;div&gt;&lt;p&gt;New AutosaveAssociation patch, updated for edge and normalized
into 1 diff.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-21T15:57:05+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-21T15:57:11+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>New NestedAttributes patch, updated for edge and normalized into 1 diff.</body>
      <body-html>&lt;div&gt;&lt;p&gt;New NestedAttributes patch, updated for edge and normalized into
1 diff.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-21T15:57:29+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-21T15:57:34+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">4</attachments-count>
      <body>How will this handle validation for multiple records, e.g. when you have a project which has_many comments and in your form template you're using fields_for to render these, will validation errors for individual projects be added to the correct fields? (so that field_error_proc works out of the box).

Also I saw that for has_one associations, you're adding an error for author.name to the parent model as author_name.. What if I'm having an actual author_name field on the parent?

I think validation is the hardest part here and we should try to do it properly right away.. Why do we even need to add it to the parent model?
Wouldn't it be sufficient and cleaner to just refactor the form helpers that actually add the errors so that they will look for errors in the associated objects?

Last but not least there is a typo/broken sentence in line 205 of the nested_attributes patch. ;)


Thanks a lot for your effort to finally get this right and if you need any help, let me know.
I'd like to contribute as well, maybe you can get me into the boat?
pascal DOT ehlert AT odadata DOT eu</body>
      <body-html>&lt;div&gt;&lt;p&gt;How will this handle validation for multiple records, e.g. when
you have a project which has_many comments and in your form
template you're using fields_for to render these, will validation
errors for individual projects be added to the correct fields? (so
that field_error_proc works out of the box).&lt;/p&gt;
&lt;p&gt;Also I saw that for has_one associations, you're adding an error
for author.name to the parent model as author_name.. What if I'm
having an actual author_name field on the parent?&lt;/p&gt;
&lt;p&gt;I think validation is the hardest part here and we should try to
do it properly right away.. Why do we even need to add it to the
parent model? Wouldn't it be sufficient and cleaner to just
refactor the form helpers that actually add the errors so that they
will look for errors in the associated objects?&lt;/p&gt;
&lt;p&gt;Last but not least there is a typo/broken sentence in line 205
of the nested_attributes patch. ;)&lt;/p&gt;
&lt;p&gt;Thanks a lot for your effort to finally get this right and if
you need any help, let me know. I'd like to contribute as well,
maybe you can get me into the boat? pascal DOT ehlert AT odadata
DOT eu&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-21T16:42:33+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-21T16:42:36+00:00</updated-at>
      <user-id type="integer">19954</user-id>
      <user-name>Pascal Ehlert</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">4</attachments-count>
      <body>Yes the validations will be added to the correct fields, just as it is right now.

If you have an author_name field on the parent and an author which has a name it would seem there is unnecessary overlap, so it seems as a non-issue to me at least for now. Unless someone can give me a real life example of breakage of course :)

The validation messages are added to the parent because in our case I want only 1 error messages list at the top of the form instead of multiple ones breaking the complete layout (and it's ugly anyways). But note that of course the individual fields are still marked as a fieldWithErrors.

Ah yes that sentence is wrong, thanks for reading it!

If you would like to help out then please checkout the complex-form-examples and play with it and the patches. Thanks in advance :)</body>
      <body-html>&lt;div&gt;&lt;p&gt;Yes the validations will be added to the correct fields, just as
it is right now.&lt;/p&gt;
&lt;p&gt;If you have an author_name field on the parent and an author
which has a name it would seem there is unnecessary overlap, so it
seems as a non-issue to me at least for now. Unless someone can
give me a real life example of breakage of course :)&lt;/p&gt;
&lt;p&gt;The validation messages are added to the parent because in our
case I want only 1 error messages list at the top of the form
instead of multiple ones breaking the complete layout (and it's
ugly anyways). But note that of course the individual fields are
still marked as a fieldWithErrors.&lt;/p&gt;
&lt;p&gt;Ah yes that sentence is wrong, thanks for reading it!&lt;/p&gt;
&lt;p&gt;If you would like to help out then please checkout the
complex-form-examples and play with it and the patches. Thanks in
advance :)&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-21T17:01:59+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-21T17:02:03+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">4</attachments-count>
      <body>Sounds good to me.

Only the author_name issue kinda bugs me, it may be an unnecessary overlap in most cases, but can we justify to break peoples applications by saying &quot;the field names they're using are wrong&quot;?

And your argument with the multiple lists is one more reason for me to patch error_messages_for instead of adding them to the parent model.
It's not only the naming issue, it's also that it doesn't feel too clean for me to ignore the separation their.

Just my 2 cents, I'd like to see some further discussion. (Although I'm strongly for getting this into core asap).</body>
      <body-html>&lt;div&gt;&lt;p&gt;Sounds good to me.&lt;/p&gt;
&lt;p&gt;Only the author_name issue kinda bugs me, it may be an
unnecessary overlap in most cases, but can we justify to break
peoples applications by saying &quot;the field names they're using are
wrong&quot;?&lt;/p&gt;
&lt;p&gt;And your argument with the multiple lists is one more reason for
me to patch error_messages_for instead of adding them to the parent
model. It's not only the naming issue, it's also that it doesn't
feel too clean for me to ignore the separation their.&lt;/p&gt;
&lt;p&gt;Just my 2 cents, I'd like to see some further discussion.
(Although I'm strongly for getting this into core asap).&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-21T17:09:24+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-21T17:09:29+00:00</updated-at>
      <user-id type="integer">19954</user-id>
      <user-name>Pascal Ehlert</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">4</attachments-count>
      <body>Fixed error in sentence. Thanks Pascal.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Fixed error in sentence. Thanks Pascal.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-21T17:10:03+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-21T17:10:06+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>Well, willingly breaking someone's code would indeed be bad :)
What I meant was that it's justified for _us_ to assume it won't break any code. And like I said, if someone would popup with a valid reason for why it breaks, I will definitely fix it.

About the other issue, I personally think it's fine that the parent knows of the errors of its children. Because ultimately you are only dealing with that parent object and saving its children should be its responsibility so you should be able to query the possible errors. Maybe moving it into a separate Errors object would help? (#nested_errors)</body>
      <body-html>&lt;div&gt;&lt;p&gt;Well, willingly breaking someone's code would indeed be bad :)
What I meant was that it's justified for &lt;em&gt;us&lt;/em&gt; to assume it
won't break any code. And like I said, if someone would popup with
a valid reason for why it breaks, I will definitely fix it.&lt;/p&gt;
&lt;p&gt;About the other issue, I personally think it's fine that the
parent knows of the errors of its children. Because ultimately you
are only dealing with that parent object and saving its children
should be its responsibility so you should be able to query the
possible errors. Maybe moving it into a separate Errors object
would help? (#nested_errors)&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-21T19:57:10+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-21T19:57:12+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>Yes, that was my thought as well.. Having a nested_errors accessor that directly queries the child error objects.

That way we could keep it separated but it would still be accessible from the parent object (which indeed is a good idea).</body>
      <body-html>&lt;div&gt;&lt;p&gt;Yes, that was my thought as well.. Having a nested_errors
accessor that directly queries the child error objects.&lt;/p&gt;
&lt;p&gt;That way we could keep it separated but it would still be
accessible from the parent object (which indeed is a good
idea).&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-21T23:47:40+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-21T23:47:43+00:00</updated-at>
      <user-id type="integer">19954</user-id>
      <user-name>Pascal Ehlert</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>Updated the patch to remove the optional second argument for the fields_for block as discussed with Michael. The collection member is simply available through foo_form#object.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Updated the patch to remove the optional second argument for the
fields_for block as discussed with Michael. The collection member
is simply available through foo_form#object.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-22T10:44:47+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-22T10:44:51+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>@Pascal After giving it some more thought, and discussing with Michael, I have decided to mark this as a &quot;could do later&quot; TODO. (I have a few others as well.) I don't think it's an issue to deal with right away for this specific patch.

Once the patch is applied I will create tickets for these TODO's.
This should also, for instance, make it easier for you to work on if you wish.</body>
      <body-html>&lt;div&gt;&lt;p&gt;@Pascal After giving it some more thought, and discussing with
Michael, I have decided to mark this as a &quot;could do later&quot; TODO. (I
have a few others as well.) I don't think it's an issue to deal
with right away for this specific patch.&lt;/p&gt;
&lt;p&gt;Once the patch is applied I will create tickets for these
TODO's. This should also, for instance, make it easier for you to
work on if you wish.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-22T10:49:08+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-22T10:49:11+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>That's reasonable and speeding the process up a little is a good thing. :)
Thanks again and I hope this will make it into trunk quickly now.

I will then comment on the other tickets (with patches that time ;)).</body>
      <body-html>&lt;div&gt;&lt;p&gt;That's reasonable and speeding the process up a little is a good
thing. :) Thanks again and I hope this will make it into trunk
quickly now.&lt;/p&gt;
&lt;p&gt;I will then comment on the other tickets (with patches that time
;)).&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-22T11:32:25+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-22T11:32:29+00:00</updated-at>
      <user-id type="integer">19954</user-id>
      <user-name>Pascal Ehlert</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>@Pascal Awesome, thanks again for your feedback.</body>
      <body-html>&lt;div&gt;&lt;p&gt;@Pascal Awesome, thanks again for your feedback.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-22T12:17:12+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-22T12:17:14+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>New patch:
Renamed accept_nested_attributes_for method to accepts_nested_attributes_for.</body>
      <body-html>&lt;div&gt;&lt;p&gt;New patch: Renamed accept_nested_attributes_for method to
accepts_nested_attributes_for.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-27T10:35:24+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-27T10:35:30+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>That patch doesn't apply to master any more.  If you can rebase the
latest version, I think we're good to go!</body>
      <body-html>&lt;div&gt;&lt;p&gt;That patch doesn't apply to master any more. If you can rebase
the latest version, I think we're good to go!&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-29T04:20:23+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-29T04:20:26+00:00</updated-at>
      <user-id type="integer">141</user-id>
      <user-name>Michael Koziarski</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>Updated nested_attributes.diff for edge.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Updated nested_attributes.diff for edge.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-29T08:31:33+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-29T08:31:37+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>I came across this via the Rails blog post. I'm interested because I have been working on solving a similar problem through a plugin I have called [Conductor](http://github.com/jonleighton/conductor/tree/master).

My initial reaction is that this seems very good. I'm pleased to see the problem being addressed in core Rails; whilst I am happy with the API I've come up with for my plugin, this definitely requires less cognitive overhead, which is obviously a good thing.

I'm not going to comment on the implementation (don't have time to study it properly), but with regard to the API I worry that putting this directly into ActiveRecord is a step too far. There's a lot of &quot;hacking&quot; in the syntax of the parameters which exist purely to overcome the limitations of HTTP parameters and HTML forms. (For instance &quot;_delete&quot;, and &quot;new_x&quot;.)

That was the idea behind having a &quot;conductor&quot; as a separate object - it acts as a buffer between the controller in the model. However I think using a completely separate object is probably the opposite extreme and I wouldn't advocate putting that into Rails either.

With regard to syntax for the parameters, I vastly prefer Approach 1 [here](http://gist.github.com/10793), as it contains nothing which is specific to HTTP/HTML. The issue with implementing it is communicating the array over HTTP and HTML validation of the form.

In my conductor plugin I use an indexed hash like in approach 4. It's a bit more ugly but solves the problem. An ideal solution might be to have ActionController automatically convert &quot;indexed&quot; arrays from the request into &quot;real&quot; arrays in the params hash. I don't know though; perhaps that would be too magic.

Anyway, in general I think this looks very promising, though I don't particularly like HTTP workarounds creeping into ActiveRecord.</body>
      <body-html>&lt;div&gt;&lt;p&gt;I came across this via the Rails blog post. I'm interested
because I have been working on solving a similar problem through a
plugin I have called &lt;a href=&quot;http://github.com/jonleighton/conductor/tree/master&quot;&gt;Conductor&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;My initial reaction is that this seems very good. I'm pleased to
see the problem being addressed in core Rails; whilst I am happy
with the API I've come up with for my plugin, this definitely
requires less cognitive overhead, which is obviously a good
thing.&lt;/p&gt;
&lt;p&gt;I'm not going to comment on the implementation (don't have time
to study it properly), but with regard to the API I worry that
putting this directly into ActiveRecord is a step too far. There's
a lot of &quot;hacking&quot; in the syntax of the parameters which exist
purely to overcome the limitations of HTTP parameters and HTML
forms. (For instance &quot;_delete&quot;, and &quot;new_x&quot;.)&lt;/p&gt;
&lt;p&gt;That was the idea behind having a &quot;conductor&quot; as a separate
object - it acts as a buffer between the controller in the model.
However I think using a completely separate object is probably the
opposite extreme and I wouldn't advocate putting that into Rails
either.&lt;/p&gt;
&lt;p&gt;With regard to syntax for the parameters, I vastly prefer
Approach 1 &lt;a href=&quot;http://gist.github.com/10793&quot;&gt;here&lt;/a&gt;, as it
contains nothing which is specific to HTTP/HTML. The issue with
implementing it is communicating the array over HTTP and HTML
validation of the form.&lt;/p&gt;
&lt;p&gt;In my conductor plugin I use an indexed hash like in approach 4.
It's a bit more ugly but solves the problem. An ideal solution
might be to have ActionController automatically convert &quot;indexed&quot;
arrays from the request into &quot;real&quot; arrays in the params hash. I
don't know though; perhaps that would be too magic.&lt;/p&gt;
&lt;p&gt;Anyway, in general I think this looks very promising, though I
don't particularly like HTTP workarounds creeping into
ActiveRecord.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-29T23:06:24+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-29T23:06:28+00:00</updated-at>
      <user-id type="integer">11330</user-id>
      <user-name>Jon Leighton</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>Thanks for your feedback Jon.

Rest assured that the '_delete' and 'new_x' keys have nothing to do with any HTTP workarounds :)

However, if you care to investigate an alternative API feel free to submit a patch.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Thanks for your feedback Jon.&lt;/p&gt;
&lt;p&gt;Rest assured that the '_delete' and 'new_x' keys have nothing to
do with any HTTP workarounds :)&lt;/p&gt;
&lt;p&gt;However, if you care to investigate an alternative API feel free
to submit a patch.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-30T09:50:51+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-30T09:50:54+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>Eloy, tried to apply your Jan 29th patch to the current master branch (commit ed0e5640879fd42c00fc5900e0355a0ea1dcf2ad) but it won't apply.  Any chance of an updated patch - unless the commit to master is coming in the next day or so?</body>
      <body-html>&lt;div&gt;&lt;p&gt;Eloy, tried to apply your Jan 29th patch to the current master
branch (commit ed0e5640879fd42c00fc5900e0355a0ea1dcf2ad) but it
won't apply. Any chance of an updated patch - unless the commit to
master is coming in the next day or so?&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-31T04:51:58+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-31T04:52:04+00:00</updated-at>
      <user-id type="integer">26903</user-id>
      <user-name>Kip Cole</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>Created a new patch because apparently for some reason my format-patch skills fail&#8230; This is just 1 patch with all patches combined in one. Here's the commit message I compiled:

Added the association accessor methods `association_instance_set' and `association_instance_get'. Replaced all code with this which was accessing the association ivars directly. See #1728.

Fixed assert_queries to _not_ count BEGIN and COMMIT queries. See #1732.

Added AutosaveAssociation, which is a module that takes care of 
automatically saving your associations when the parent is saved. In 
addition to saving, it also destroys any associations that were marked for 
destruction.

Added NestedAttributes module which adds the accepts_nested_attributes_for 
class method. With this method an attributes writer is defined for an 
association. This allows you to set and update attributes of associated 
models through the parent model as well as destroying them. Also included 
are adjustments to FormBuilder#fields_for to support such nested model 
attributes.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Created a new patch because apparently for some reason my
format-patch skills fail&amp;#8230; This is just 1 patch with all
patches combined in one. Here's the commit message I compiled:&lt;/p&gt;
&lt;p&gt;Added the association accessor methods
&lt;code&gt;association_instance_set'
and&lt;/code&gt;association_instance_get'. Replaced all code with this
which was accessing the association ivars directly. See &lt;a href=&quot;/projects/8994/tickets/1728&quot; title=&quot;Ticket #1728&quot;&gt;#1728&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Fixed assert_queries to &lt;em&gt;not&lt;/em&gt; count BEGIN and COMMIT
queries. See &lt;a href=&quot;/projects/8994/tickets/1732&quot; title=&quot;Ticket #1732&quot;&gt;#1732&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Added AutosaveAssociation, which is a module that takes care of
automatically saving your associations when the parent is saved. In
addition to saving, it also destroys any associations that were
marked for destruction.&lt;/p&gt;
&lt;p&gt;Added NestedAttributes module which adds the
accepts_nested_attributes_for class method. With this method an
attributes writer is defined for an association. This allows you to
set and update attributes of associated models through the parent
model as well as destroying them. Also included are adjustments to
FormBuilder#fields_for to support such nested model attributes.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-31T18:03:29+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-31T18:03:32+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>And the new patch.</body>
      <body-html>&lt;div&gt;&lt;p&gt;And the new patch.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-31T18:03:58+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-01-31T18:04:04+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">4</attachments-count>
      <body>(from [ec8f04584479aff895b0b511a7ba1e9d33f84067]) Add support for nested object forms to ActiveRecord and the helpers in ActionPack

Signed-Off-By: Michael Koziarski &lt;michael@koziarski.com&gt;

[#1202 state:committed]
http://github.com/rails/rails/commit/ec8f04584479aff895b0b511a7ba1e9d33f84067</body>
      <body-html>&lt;div&gt;&lt;p&gt;(from [ec8f04584479aff895b0b511a7ba1e9d33f84067]) Add support
for nested object forms to ActiveRecord and the helpers in
ActionPack&lt;/p&gt;
&lt;p&gt;Signed-Off-By: Michael Koziarski &lt;a href=&quot;mailto:michael@koziarski.com&quot;&gt;michael@koziarski.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;/projects/8994/tickets/1202&quot; title=&quot;Ticket #1202&quot;&gt;#1202&lt;/a&gt; state:committed] &lt;a href=&quot;http://github.com/rails/rails/commit/ec8f04584479aff895b0b511a7ba1e9d33f84067&quot;&gt;
http://github.com/rails/rails/co...&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2009-02-01T02:02:21+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- 
:state: new
</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>committed</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-02-01T02:02:24+00:00</updated-at>
      <user-id type="integer">17393</user-id>
      <user-name>Repository</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">4</attachments-count>
      <body>This doesn't work well when validating the relationship. For example, http://gist.github.com/82527. At least I've seen no docs on it yet (and probably haven't looked hard enough...)

This is a problem when creating new objects.</body>
      <body-html>&lt;div&gt;&lt;p&gt;This doesn't work well when validating the relationship. For
example, &lt;a href=&quot;http://gist.github.com/82527&quot;&gt;http://gist.github.com/82527&lt;/a&gt;. At
least I've seen no docs on it yet (and probably haven't looked hard
enough...)&lt;/p&gt;
&lt;p&gt;This is a problem when creating new objects.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2009-03-20T19:50:50+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>committed</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-03-20T19:50:55+00:00</updated-at>
      <user-id type="integer">18189</user-id>
      <user-name>orangechicken</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">4</attachments-count>
      <body>@orangechicken See this ticket #1943.</body>
      <body-html>&lt;div&gt;&lt;p&gt;@orangechicken See this ticket &lt;a href=&quot;/projects/8994/tickets/1943&quot; title=&quot;Ticket #1943&quot;&gt;#1943&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2009-03-21T00:11:12+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>committed</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-03-21T00:11:16+00:00</updated-at>
      <user-id type="integer">8406</user-id>
      <user-name>Eloy Duran</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">8406</assigned-user-id>
      <attachments-count type="integer">4</attachments-count>
      <body>I am using nested forms on a person model that has many pictures.
I would like to allow the user to remove on or more of the associated
pictures from the person using nested forms as suggested by Ryan Bates.

However delete will delete the picture not remove the associatioon
I can do it in the controller, but it should be done in the same way as
delete is performed using attribute _delete
Is there a _remove attribute or any other way to solve the problem 
(e.g. that  a command like allow_remove=true)

Another problem is that it seems as nested forms do not validate the
attributes of the associated object in this case picture (the name should be unique).
I have solved the problem by a fix in the controller, but shouldn't that be a
feature of nested forms

Any comment would be much appreciated</body>
      <body-html>&lt;div&gt;&lt;p&gt;I am using nested forms on a person model that has many
pictures.&lt;br&gt;
I would like to allow the user to remove on or more of the
associated&lt;br&gt;
pictures from the person using nested forms as suggested by Ryan
Bates.&lt;/p&gt;
&lt;p&gt;However delete will delete the picture not remove the
associatioon&lt;br&gt;
I can do it in the controller, but it should be done in the same
way as&lt;br&gt;
delete is performed using attribute &lt;em&gt;delete&lt;br&gt;
Is there a&lt;/em&gt; remove attribute or any other way to solve the
problem&lt;br&gt;
(e.g. that a command like allow_remove=true)&lt;/p&gt;
&lt;p&gt;Another problem is that it seems as nested forms do not validate
the&lt;br&gt;
attributes of the associated object in this case picture (the name
should be unique).&lt;br&gt;
I have solved the problem by a fix in the controller, but shouldn't
that be a&lt;br&gt;
feature of nested forms&lt;/p&gt;
&lt;p&gt;Any comment would be much appreciated&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2009-08-02T08:42:23+01:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- 
:assigned_user: 141
</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>committed</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-08-02T08:42:27+01:00</updated-at>
      <user-id type="integer">64804</user-id>
      <user-name>Hans</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Eloy Duran</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">4</attachments-count>
      <body>Sorry about the change of assigned user - my mistake
Have changed the code and then the validation seems to work
However, the problem of removing / deleting associations is still a problem</body>
      <body-html>&lt;div&gt;&lt;p&gt;Sorry about the change of assigned user - my mistake&lt;br&gt;
Have changed the code and then the validation seems to work&lt;br&gt;
However, the problem of removing / deleting associations is still a
problem&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2009-08-03T09:27:20+01:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- 
:assigned_user: 8406
</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>committed</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-08-03T09:27:25+01:00</updated-at>
      <user-id type="integer">64804</user-id>
      <user-name>Hans</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">4</attachments-count>
      <body>Sorry for the term, but {&quot;id&quot; =&gt; 22, &quot;_delete&quot; =&gt; 1} is retarded. How about checking that attributes hash, and if it contains _child key_ and is set to nil, then destroy that child?

That means, for has_one associations, it should be enough to pass a hash like:

@@@ ruby
{ :author =&gt; nil }
@@@

...and for deleting in has_many:

@@@ ruby
{ :comments =&gt; {
  22 =&gt; nil,
  23 =&gt; nil
}}
@@@

...and for deleting, updating and creating in one go:

@@@ ruby
{ :comments =&gt; {
  22 =&gt; nil,
  23 =&gt; { :title =&gt; 'twenytri' },
  0  =&gt; { :title =&gt; 'titty', :body =&gt; 'ritty' }
}}
@@@

However, that 0 key is obvious hack, any ideas on that?</body>
      <body-html>&lt;div&gt;&lt;p&gt;Sorry for the term, but {&quot;id&quot; =&amp;gt; 22, &quot;&lt;em&gt;delete&quot; =&amp;gt; 1} is
retarded. How about checking that attributes hash, and if it
contains&lt;/em&gt; child key_ and is set to nil, then destroy that
child?&lt;/p&gt;
&lt;p&gt;That means, for has_one associations, it should be enough to
pass a hash like:&lt;/p&gt;
&lt;pre&gt;
&lt;code class=&quot;ruby&quot;&gt;{ :author =&amp;gt; nil }&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;...and for deleting in has_many:&lt;/p&gt;
&lt;pre&gt;
&lt;code class=&quot;ruby&quot;&gt;{ :comments =&amp;gt; {
  22 =&amp;gt; nil,
  23 =&amp;gt; nil
}}&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;...and for deleting, updating and creating in one go:&lt;/p&gt;
&lt;pre&gt;
&lt;code class=&quot;ruby&quot;&gt;{ :comments =&amp;gt; {
  22 =&amp;gt; nil,
  23 =&amp;gt; { :title =&amp;gt; 'twenytri' },
  0  =&amp;gt; { :title =&amp;gt; 'titty', :body =&amp;gt; 'ritty' }
}}&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;However, that 0 key is obvious hack, any ideas on that?&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2009-12-03T14:45:23+00:00</created-at>
      <creator-id type="integer">8406</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">1202</number>
      <permalink>add-attributes-writer-method-for-an-association</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>committed</state>
      <tag>actionview activerecord enhancement patch</tag>
      <title>Add attributes writer method for an association.</title>
      <updated-at type="datetime">2009-12-03T14:45:27+00:00</updated-at>
      <user-id type="integer">22610</user-id>
      <user-name>Dusan Maliarik</user-name>
      <creator-name>Eloy Duran</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/1202</url>
      <milestone-title nil="true"></milestone-title>
    </version>
  </versions>
  <attachments type="array">
    <attachment type="Attachment">
      <code>6d85e994539d419e87b64c105535f01a400292c6</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2008-12-17T16:05:51+00:00</created-at>
      <filename>nested_changes.diff</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">72160</id>
      <size type="integer">3369</size>
      <uploader-id type="integer">11785</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://rails.lighthouseapp.com/attachments/72160/nested_changes.diff</url>
    </attachment>
    <attachment type="Attachment">
      <code>6bbc88bbce51c332a4f877be1ae72b6d0f975efc</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2009-01-21T15:57:05+00:00</created-at>
      <filename>3.autosave_association.diff</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">80432</id>
      <size type="integer">32762</size>
      <uploader-id type="integer">8406</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://rails.lighthouseapp.com/attachments/80432/3.autosave_association.diff</url>
    </attachment>
    <attachment type="Attachment">
      <code>1656cc415afe2eddf747365afc54978dbcc7140b</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2009-01-29T08:31:33+00:00</created-at>
      <filename>4.nested_attributes.diff</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">82796</id>
      <size type="integer">65261</size>
      <uploader-id type="integer">8406</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://rails.lighthouseapp.com/attachments/82796/4.nested_attributes.diff</url>
    </attachment>
    <attachment type="Attachment">
      <code>c83c1fc5222bc39f5173aba37afbd560dc6843df</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2009-01-31T18:03:58+00:00</created-at>
      <filename>association_instance_accessors_and_autosave_association_and_nested_attributes.diff</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">83579</id>
      <size type="integer">85906</size>
      <uploader-id type="integer">8406</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://rails.lighthouseapp.com/attachments/83579/association_instance_accessors_and_autosave_association_and_nested_attributes.diff</url>
    </attachment>
  </attachments>
</ticket>
