From f82adc7c5addb4f9bf6b9cb3f1fcf3fb47505e53 Mon Sep 17 00:00:00 2001 From: Eloy Duran Date: Thu, 31 Dec 2009 14:03:04 +0100 Subject: Add AssociationReflection#collection_association? which returns true if it's for a has_many or has_and_belongs_to_many association. --- activerecord/lib/active_record/reflection.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index b751c9ad68..69772bf9bb 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -252,10 +252,17 @@ module ActiveRecord end end + # Returns whether or not this association reflection is for a collection + # association. Returns +true+ if the +macro+ is one of +has_many+ or + # +has_and_belongs_to_many+, +false+ otherwise. + def collection_association? + [:has_many, :has_and_belongs_to_many].include?(macro) + end + private def derive_class_name class_name = name.to_s.camelize - class_name = class_name.singularize if [ :has_many, :has_and_belongs_to_many ].include?(macro) + class_name = class_name.singularize if collection_association? class_name end -- cgit v1.2.3