Permalink
Browse files

Refactor AssociationScope#get_bind_values

Added #join_id_for(owner) to reflection to avoid accessing the source_macro
  • Loading branch information...
eric-chahin committed May 5, 2014
1 parent 4efb0f3 commit bf4a80223b77d84ad158fcc057eef13327773aa2
@@ -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

0 comments on commit bf4a802

Please sign in to comment.