From 403c7d46eeaca60fa82be93d5ecd898ee4a8590e Mon Sep 17 00:00:00 2001 From: Mike Gunderloy Date: Sun, 1 Feb 2009 13:39:49 -0600 Subject: Update associations guide for 2.3 --- railties/doc/guides/source/association_basics.txt | 41 ++++++++++++----------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'railties') diff --git a/railties/doc/guides/source/association_basics.txt b/railties/doc/guides/source/association_basics.txt index 95d7397558..80605c1e83 100644 --- a/railties/doc/guides/source/association_basics.txt +++ b/railties/doc/guides/source/association_basics.txt @@ -624,7 +624,7 @@ end The +belongs_to+ association supports these options: -// * +:accessible+ +* +:autosave+ * +:class_name+ * +:conditions+ * +:counter_cache+ @@ -636,10 +636,10 @@ The +belongs_to+ association supports these options: * +:select+ * +:validate+ -// ===== +:accessible+ -// -// The +:accessible+ option is the association version of +ActiveRecord::Base#attr_accessible+. If you set the +:accessible+ option to true, then mass // assignment is allowed for this association. -// +===== +:autosave+ + +If you set the +:autosave+ option to +true+, Rails will save any loaded members and destroy members that are marked for destruction whenever you save the parent object. + ===== +:class_name+ If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if an order belongs to a customer, but the actual name of the model containing customers is +Patron+, you'd set things up this way: @@ -877,8 +877,8 @@ end The +has_one+ association supports these options: -// * +:accessible+ * +:as+ +* +:autosave+ * +:class_name+ * +:conditions+ * +:dependent+ @@ -893,14 +893,14 @@ The +has_one+ association supports these options: * +:through+ * +:validate+ -// ===== +:accessible+ -// -// The +:accessible+ option is the association version of +ActiveRecord::Base#attr_accessible+. If you set the +:accessible+ option to true, then mass // assignment is allowed for this association. -// ===== +:as+ Setting the +:as+ option indicates that this is a polymorphic association. Polymorphic associations are discussed in detail later in this guide. +===== +:autosave+ + +If you set the +:autosave+ option to +true+, Rails will save any loaded members and destroy members that are marked for destruction whenever you save the parent object. + ===== +:class_name+ If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if a supplier has an account, but the actual name of the model containing accounts is Billing, you'd set things up this way: @@ -1181,8 +1181,8 @@ end The +has_many+ association supports these options: -// * +:accessible+ * +:as+ +* +:autosave+ * +:class_name+ * +:conditions+ * +:counter_sql+ @@ -1204,14 +1204,14 @@ The +has_many+ association supports these options: * +:uniq+ * +:validate+ -// ===== +:accessible+ -// -// The +:accessible+ option is the association version of +ActiveRecord::Base#attr_accessible+. If you set the +:accessible+ option to true, then mass // assignment is allowed for this association. -// ===== +:as+ Setting the +:as+ option indicates that this is a polymorphic association, as discussed earlier in this guide. +===== +:autosave+ + +If you set the +:autosave+ option to +true+, Rails will save any loaded members and destroy members that are marked for destruction whenever you save the parent object. + ===== +:class_name+ If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if a customer has many orders, but the actual name of the model containing orders is +Transaction+, you'd set things up this way: @@ -1566,8 +1566,8 @@ end The +has_and_belongs_to_many+ association supports these options: -// * +:accessible+ * +:association_foreign_key+ +* +:autosave+ * +:class_name+ * +:conditions+ * +:counter_sql+ @@ -1587,10 +1587,6 @@ The +has_and_belongs_to_many+ association supports these options: * +:uniq+ * +:validate+ -// ===== +:accessible+ -// -// The +:accessible+ option is the association version of +ActiveRecord::Base#attr_accessible+. If you set the +:accessible+ option to true, then mass // assignment is allowed for this association. -// ===== +:association_foreign_key+ By convention, Rails guesses that the column in the join table used to hold the foreign key pointing to the other model is the name of that model with the suffix +_id+ added. The +:association_foreign_key+ option lets you set the name of the foreign key directly: @@ -1605,6 +1601,10 @@ class User < ActiveRecord::Base end ------------------------------------------------------- +===== +:autosave+ + +If you set the +:autosave+ option to +true+, Rails will save any loaded members and destroy members that are marked for destruction whenever you save the parent object. + ===== +:class_name+ If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if a part has many assemblies, but the actual name of the model containing assemblies is +Gadget+, you'd set things up this way: @@ -1841,6 +1841,7 @@ Extensions can refer to the internals of the association proxy using these three http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/11[Lighthouse ticket] +* February 1, 2009: Added +:autosave+ option link:../authors.html#mgunderloy[Mike Gunderloy] * September 28, 2008: Corrected +has_many :through+ diagram, added polymorphic diagram, some reorganization by link:../authors.html#mgunderloy[Mike Gunderloy] . First release version. * September 22, 2008: Added diagrams, misc. cleanup by link:../authors.html#mgunderloy[Mike Gunderloy] (not yet approved for publication) * September 14, 2008: initial version by link:../authors.html#mgunderloy[Mike Gunderloy] (not yet approved for publication) -- cgit v1.2.3