From 695ec8e2799a2c91f93a6fb58d713137a61aa0d2 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sat, 28 Jan 2012 18:21:22 -0200 Subject: Improve active record associations guide a bit * Use right example for has_many :find method; * Reword has_many :counter_sql doc notes. --- railties/guides/source/association_basics.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides/source/association_basics.textile') diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile index 451653655f..1b443e09a8 100644 --- a/railties/guides/source/association_basics.textile +++ b/railties/guides/source/association_basics.textile @@ -1120,7 +1120,7 @@ h6(#has_many-collection-find). collection.find(...) The collection.find method finds objects within the collection. It uses the same syntax and options as +ActiveRecord::Base.find+. -@open_orders = @customer.orders.where(:open => 1) +@open_orders = @customer.orders.find(1) h6(#has_many-collection-where). collection.where(...) @@ -1242,7 +1242,7 @@ h6(#has_many-counter_sql). +:counter_sql+ Normally Rails automatically generates the proper SQL to count the association members. With the +:counter_sql+ option, you can specify a complete SQL statement to count them yourself. -NOTE: If you specify +:finder_sql+ but not +:counter_sql+, then the counter SQL will be generated by substituting +SELECT COUNT(*) FROM+ for the +SELECT ... FROM+ clause of your +:finder_sql+ statement. +NOTE: If you specify +:finder_sql+ but not +:counter_sql+, then the counter SQL will be generated by substituting the +SELECT ... FROM+ clause of your +:finder_sql+ statement by +SELECT COUNT(*) FROM+. h6(#has_many-dependent). +:dependent+ -- cgit v1.2.3 From 0d5f7dac3dbbd788763e3b6fffce40dfc7a3ba84 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Tue, 31 Jan 2012 09:40:38 -0200 Subject: Improve ar associations habtm docs a bit --- railties/guides/source/association_basics.textile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'railties/guides/source/association_basics.textile') diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile index 1b443e09a8..a55ed38d1b 100644 --- a/railties/guides/source/association_basics.textile +++ b/railties/guides/source/association_basics.textile @@ -1545,12 +1545,9 @@ h6(#has_and_belongs_to_many-collection-find). collection.find(...)< The collection.find method finds objects within the collection. It uses the same syntax and options as +ActiveRecord::Base.find+. It also adds the additional condition that the object must be in the collection. -@new_assemblies = @part.assemblies.all( - :conditions => ["created_at > ?", 2.days.ago]) +@assembly = @part.assemblies.find(1) -NOTE: Beginning with Rails 3, supplying options to the +ActiveRecord::Base.find+ method is discouraged. Use collection.where instead when you need to pass conditions. - h6(#has_and_belongs_to_many-collection-where). collection.where(...) The collection.where method finds objects within the collection based on the conditions supplied but the objects are loaded lazily meaning that the database is queried only when the object(s) are accessed. It also adds the additional condition that the object must be in the collection. @@ -1669,7 +1666,7 @@ h6(#has_and_belongs_to_many-counter_sql). +:counter_sql+ Normally Rails automatically generates the proper SQL to count the association members. With the +:counter_sql+ option, you can specify a complete SQL statement to count them yourself. -NOTE: If you specify +:finder_sql+ but not +:counter_sql+, then the counter SQL will be generated by substituting +SELECT COUNT(*) FROM+ for the +SELECT ... FROM+ clause of your +:finder_sql+ statement. +NOTE: If you specify +:finder_sql+ but not +:counter_sql+, then the counter SQL will be generated by substituting the +SELECT ... FROM+ clause of your +:finder_sql+ statement by +SELECT COUNT(*) FROM+. h6(#has_and_belongs_to_many-delete_sql). +:delete_sql+ -- cgit v1.2.3