From b5ba377b784c58db7b7fb878862a550ae57beb95 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 27 Dec 2005 05:41:23 +0000 Subject: Added option to Base.reflection_of_all_associations to specify a specific association to scope the call. For example Base.reflection_of_all_associations(:has_many) [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3357 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/reflection.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 87a05086fc..9bac82f5ce 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -34,9 +34,11 @@ module ActiveRecord reflections[aggregation].is_a?(AggregateReflection) ? reflections[aggregation] : nil end - # Returns an array of AssociationReflection objects for all the aggregations in the class. - def reflect_on_all_associations - reflections.values.select { |reflection| reflection.is_a?(AssociationReflection) } + # 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. + 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 end # Returns the AssociationReflection object for the named +aggregation+ (use the symbol). Example: -- cgit v1.2.3