diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-07 20:13:07 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-07 20:13:07 +0100 |
commit | 423e2acbb7110961a2774ccd191261c031b83d7a (patch) | |
tree | f21f347bc496098226b9b56fd5f459af372d9cdb /activerecord/lib/active_record/reflection.rb | |
parent | 47a5fd4c4ba447c997c0a029adfa80d8b790b25a (diff) | |
parent | 9550916903c931161f04a98091fba712d7fa5c1d (diff) | |
download | rails-423e2acbb7110961a2774ccd191261c031b83d7a.tar.gz rails-423e2acbb7110961a2774ccd191261c031b83d7a.tar.bz2 rails-423e2acbb7110961a2774ccd191261c031b83d7a.zip |
Merge remote branch 'eloy/master'
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index b751c9ad68..d6fad5cf29 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -252,10 +252,33 @@ 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? + if @collection_association.nil? + @collection_association = [:has_many, :has_and_belongs_to_many].include?(macro) + end + @collection_association + end + + # Returns whether or not the association should be validated as part of + # the parent's validation. + # + # Unless you explicitely disable validation with + # <tt>:validate => false</tt>, it will take place when: + # + # * you explicitely enable validation; <tt>:validate => true</tt> + # * you use autosave; <tt>:autosave => true</tt> + # * the association is a +has_many+ association + def validate? + !options[:validate].nil? ? options[:validate] : (options[:autosave] == true || macro == :has_many) + 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 |