提交 84093c66 编写于 作者: R Rafael Mendonça França

Merge pull request #16351 from...

Merge pull request #16351 from eileencodes/finish-refactoring-macro-to-eliminate-checking-against-symbols

Redefine macro checks for reflections
......@@ -124,7 +124,7 @@ def inverse_updates_counter_cache?(reflection = reflection())
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
......
......@@ -34,7 +34,7 @@ def reset_counters(id, *counters)
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({
......
......@@ -431,14 +431,10 @@ def validate?
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 @@ def initialize(name, scope, options, active_record)
def macro; :has_many; end
def collection?
true
end
def collection?; true; end
end
class HasOneReflection < AssociationReflection #:nodoc:
......@@ -596,6 +590,8 @@ def initialize(name, scope, options, active_record)
end
def macro; :has_one; end
def has_one?; true; end
end
class BelongsToReflection < AssociationReflection #:nodoc:
......@@ -604,6 +600,8 @@ def initialize(name, scope, options, active_record)
end
def macro; :belongs_to; end
def belongs_to?; true; end
end
class HasAndBelongsToManyReflection < AssociationReflection #:nodoc:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册