onrails.org home

ActiveRecord's accepts_nested_attributes_for specification

I was trying to figure out how to use the new AvtiveRecord accepts_nested_attributes_for functionality that enables saving nested active records. In fact I will try to use that functionality from a Flex application using the RestfulX framework.

The cool thing about trying to understand Rails or ActiveRecord is that there are many tests available part of the source code which describe really well the framework. The functionality is provided by the NestedAttributes module defined in /activerecord-2.3.2/lib/active_record/nested_attributes.rb.

I just generated a basic specs from the associated test case which I included here after and this give a good idea of what the accepts_nested_attributes_for method supports:

Nested Attributes In General

Nested Attributes On A Has One Association

Nested Attributes On A Belongs To Association

Nested Attributes On A Has Many Association
and Nested Attributes On A Has And Belongs To Many Association

Fork me on GitHub