aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2006-02-28 20:13:37 +0000
committerMichael Koziarski <michael@koziarski.com>2006-02-28 20:13:37 +0000
commita117d68f0f6935a987609b28191ea8efd3da6cea (patch)
tree6ee0240c8d5293228e4f89428c1d501aff9eb0ac /activerecord
parent9ad6e1a62818032cb58ae58f093fb528fe521307 (diff)
downloadrails-a117d68f0f6935a987609b28191ea8efd3da6cea.tar.gz
rails-a117d68f0f6935a987609b28191ea8efd3da6cea.tar.bz2
rails-a117d68f0f6935a987609b28191ea8efd3da6cea.zip
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
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/reflection.rb5
1 files changed, 4 insertions, 1 deletions
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