From a117d68f0f6935a987609b28191ea8efd3da6cea Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Tue, 28 Feb 2006 20:13:37 +0000 Subject: Add more documentation for Reflection. [robby@planetargon.com]. Closes #4001 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3705 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/reflection.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 4d84cd1012..b9369feeb7 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -37,7 +37,9 @@ module ActiveRecord end # Returns an array of AssociationReflection objects for all the aggregations in the class. If you only want to reflect on a - # certain association type, pass in the symbol for that as the first parameter. + # certain association type, pass in the symbol (:has_many, :has_one, :belongs_to) for that as the first parameter. Example: + # Account.reflect_on_all_associations # returns an array of all associations + # Account.reflect_on_all_associations(:has_many) # returns an array of all has_many associations def reflect_on_all_associations(macro = nil) association_reflections = reflections.values.select { |reflection| reflection.is_a?(AssociationReflection) } macro ? association_reflections.select { |reflection| reflection.macro == macro } : association_reflections @@ -45,6 +47,7 @@ module ActiveRecord # Returns the AssociationReflection object for the named +aggregation+ (use the symbol). Example: # Account.reflect_on_association(:owner) # returns the owner AssociationReflection + # Invoice.reflect_on_association(:line_items).macro # returns :has_many def reflect_on_association(association) reflections[association].is_a?(AssociationReflection) ? reflections[association] : nil end -- cgit v1.2.3