提交 0b4cfa2b 编写于 作者: R Ryuta Kamizono

Don't expose internal methods in the associations

上级 2b5b08b8
......@@ -79,18 +79,6 @@ def scope
target_scope.merge!(association_scope)
end
# The scope for this association.
#
# Note that the association_scope is merged into the target_scope only when the
# scope method is called. This is because at that point the call may be surrounded
# by scope.scoping { ... } or with_scope { ... } etc, which affects the scope which
# actually gets built.
def association_scope
if klass
@association_scope ||= AssociationScope.scope(self)
end
end
def reset_scope
@association_scope = nil
end
......@@ -129,12 +117,6 @@ def klass
reflection.klass
end
# Can be overridden (i.e. in ThroughAssociation) to merge in other scopes (i.e. the
# through association's scope)
def target_scope
AssociationRelation.create(klass, self).merge!(klass.all)
end
def extensions
extensions = klass.default_extensions | reflection.extensions
......@@ -195,6 +177,24 @@ def create!(attributes = {}, &block)
end
private
# The scope for this association.
#
# Note that the association_scope is merged into the target_scope only when the
# scope method is called. This is because at that point the call may be surrounded
# by scope.scoping { ... } or unscoped { ... } etc, which affects the scope which
# actually gets built.
def association_scope
if klass
@association_scope ||= AssociationScope.scope(self)
end
end
# Can be overridden (i.e. in ThroughAssociation) to merge in other scopes (i.e. the
# through association's scope)
def target_scope
AssociationRelation.create(klass, self).merge!(klass.all)
end
def scope_for_create
scope.scope_for_create
end
......
......@@ -21,20 +21,6 @@ def concat(*records)
super
end
def concat_records(records)
ensure_not_nested
records = super(records, true)
if owner.new_record? && records
records.flatten.each do |record|
build_through_record(record)
end
end
records
end
def insert_record(record, validate = true, raise = false)
ensure_not_nested
......@@ -48,6 +34,20 @@ def insert_record(record, validate = true, raise = false)
end
private
def concat_records(records)
ensure_not_nested
records = super(records, true)
if owner.new_record? && records
records.flatten.each do |record|
build_through_record(record)
end
end
records
end
# The through record (built with build_record) is temporarily cached
# so that it may be reused if insert_record is subsequently called.
#
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册