diff options
author | Eloy Duran <eloy.de.enige@gmail.com> | 2009-12-31 14:03:04 +0100 |
---|---|---|
committer | Eloy Duran <eloy.de.enige@gmail.com> | 2010-01-07 13:19:48 +0100 |
commit | f82adc7c5addb4f9bf6b9cb3f1fcf3fb47505e53 (patch) | |
tree | b71e7a9af8a7742f07bcd3d5d65e50bdc3f94bb2 /activerecord/lib/active_record | |
parent | 1afa9fa5a973734852bd7a9d20a534355c221098 (diff) | |
download | rails-f82adc7c5addb4f9bf6b9cb3f1fcf3fb47505e53.tar.gz rails-f82adc7c5addb4f9bf6b9cb3f1fcf3fb47505e53.tar.bz2 rails-f82adc7c5addb4f9bf6b9cb3f1fcf3fb47505e53.zip |
Add AssociationReflection#collection_association? which returns true if it's for a has_many or has_and_belongs_to_many association.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 9 |
1 files changed, 8 insertions, 1 deletions
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 |