提交 a117d68f 编写于 作者: M Michael Koziarski

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
上级 9ad6e1a6
......@@ -37,7 +37,9 @@ def reflect_on_aggregation(aggregation)
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 @@ def reflect_on_all_associations(macro = nil)
# 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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册