提交 bf4a8022 编写于 作者: E Eric Chahin

Refactor AssociationScope#get_bind_values

Added #join_id_for(owner) to reflection to avoid accessing the source_macro
上级 4efb0f37
......@@ -47,15 +47,8 @@ def join_type
def self.get_bind_values(owner, chain)
bvs = []
chain.each_with_index do |reflection, i|
if reflection.source_macro == :belongs_to
foreign_key = reflection.foreign_key
else
foreign_key = reflection.active_record_primary_key
end
if reflection == chain.last
bvs << owner[foreign_key]
bvs << reflection.join_id_for(owner)
if reflection.type
bvs << owner.class.base_class.name
end
......
......@@ -278,6 +278,11 @@ def check_validity_of_inverse!
end
end
def join_id_for(owner) #:nodoc:
key = (source_macro == :belongs_to) ? foreign_key : active_record_primary_key
owner[key]
end
def through_reflection
nil
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册