提交 7e4b2abe 编写于 作者: Y yui-knk

Each concrete classes have responsibility to return `association_class`

上级 8dfb8760
......@@ -483,28 +483,7 @@ def belongs_to?; false; end
# Returns +true+ if +self+ is a +has_one+ reflection.
def has_one?; false; end
def association_class
case macro
when :belongs_to
if polymorphic?
Associations::BelongsToPolymorphicAssociation
else
Associations::BelongsToAssociation
end
when :has_many
if options[:through]
Associations::HasManyThroughAssociation
else
Associations::HasManyAssociation
end
when :has_one
if options[:through]
Associations::HasOneThroughAssociation
else
Associations::HasOneAssociation
end
end
end
def association_class; raise NotImplementedError; end
def polymorphic?
options[:polymorphic]
......@@ -629,6 +608,14 @@ def initialize(name, scope, options, active_record)
def macro; :has_many; end
def collection?; true; end
def association_class
if options[:through]
Associations::HasManyThroughAssociation
else
Associations::HasManyAssociation
end
end
end
class HasOneReflection < AssociationReflection # :nodoc:
......@@ -639,6 +626,14 @@ def initialize(name, scope, options, active_record)
def macro; :has_one; end
def has_one?; true; end
def association_class
if options[:through]
Associations::HasOneThroughAssociation
else
Associations::HasOneAssociation
end
end
end
class BelongsToReflection < AssociationReflection # :nodoc:
......@@ -650,6 +645,14 @@ def macro; :belongs_to; end
def belongs_to?; true; end
def association_class
if polymorphic?
Associations::BelongsToPolymorphicAssociation
else
Associations::BelongsToAssociation
end
end
def join_keys(association_klass)
key = polymorphic? ? association_primary_key(association_klass) : association_primary_key
JoinKeys.new(key, foreign_key)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册