diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-07-31 11:25:41 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-07-31 11:25:41 -0300 |
commit | 84093c662770893ad840c36f2b99204593d4a7de (patch) | |
tree | 5b59c31e37e36bd0ae5a90ef427b90685f3d5f70 | |
parent | dccdee7e2d021e700c51fc4612ff617e645ccb51 (diff) | |
parent | 8d7dea766e7a5371dab09bf4c819ff1fc28ffa31 (diff) | |
download | rails-84093c662770893ad840c36f2b99204593d4a7de.tar.gz rails-84093c662770893ad840c36f2b99204593d4a7de.tar.bz2 rails-84093c662770893ad840c36f2b99204593d4a7de.zip |
Merge pull request #16351 from eileencodes/finish-refactoring-macro-to-eliminate-checking-against-symbols
Redefine macro checks for reflections
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_association.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/counter_cache.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 16 |
3 files changed, 9 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index 2a97d0ed31..79c3d2b0f5 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -124,7 +124,7 @@ module ActiveRecord def inverse_updates_counter_named?(counter_name, reflection = reflection()) reflection.klass._reflections.values.any? { |inverse_reflection| - :belongs_to == inverse_reflection.macro && + inverse_reflection.belongs_to? && inverse_reflection.counter_cache_column == counter_name } end diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb index a33c7c64a7..f0b6afc4b4 100644 --- a/activerecord/lib/active_record/counter_cache.rb +++ b/activerecord/lib/active_record/counter_cache.rb @@ -34,7 +34,7 @@ module ActiveRecord foreign_key = has_many_association.foreign_key.to_s child_class = has_many_association.klass - reflection = child_class._reflections.values.find { |e| :belongs_to == e.macro && e.foreign_key.to_s == foreign_key && e.options[:counter_cache].present? } + reflection = child_class._reflections.values.find { |e| e.belongs_to? && e.foreign_key.to_s == foreign_key && e.options[:counter_cache].present? } counter_name = reflection.counter_cache_column stmt = unscoped.where(arel_table[primary_key].eq(object.id)).arel.compile_update({ diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 1672128aa3..21da011e8a 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -431,14 +431,10 @@ Joining, Preloading and eager loading of these associations is deprecated and wi end # Returns +true+ if +self+ is a +belongs_to+ reflection. - def belongs_to? - macro == :belongs_to - end + def belongs_to?; false; end # Returns +true+ if +self+ is a +has_one+ reflection. - def has_one? - macro == :has_one - end + def has_one?; false; end def association_class case macro @@ -585,9 +581,7 @@ Joining, Preloading and eager loading of these associations is deprecated and wi def macro; :has_many; end - def collection? - true - end + def collection?; true; end end class HasOneReflection < AssociationReflection #:nodoc: @@ -596,6 +590,8 @@ Joining, Preloading and eager loading of these associations is deprecated and wi end def macro; :has_one; end + + def has_one?; true; end end class BelongsToReflection < AssociationReflection #:nodoc: @@ -604,6 +600,8 @@ Joining, Preloading and eager loading of these associations is deprecated and wi end def macro; :belongs_to; end + + def belongs_to?; true; end end class HasAndBelongsToManyReflection < AssociationReflection #:nodoc: |