Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6225: 6226_fix_deprecated_foo_count.diff

File 6226_fix_deprecated_foo_count.diff, 0.8 kB (added by octopod, 2 years ago)

fix deprecation warning when foo_count method exists

  • activerecord/lib/active_record/deprecated_associations.rb

    old new  
    44      def deprecated_collection_count_method(collection_name)# :nodoc: 
    55        module_eval <<-"end_eval", __FILE__, __LINE__ 
    66          def #{collection_name}_count(force_reload = false) 
    7             unless has_attribute?(:#{collection_name}_count) 
     7            unless has_attribute?(:#{collection_name}_count) or respond_to?(:#{collection_name}_count) 
    88              ActiveSupport::Deprecation.warn :#{collection_name}_count 
    99            end 
    1010            #{collection_name}.reload if force_reload