Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor AssociationScope#get_bind_values

Added #join_id_for(owner) to reflection to avoid accessing the source_macro
  • Loading branch information...
commit bf4a80223b77d84ad158fcc057eef13327773aa2 1 parent 4efb0f3
@eric-chahin eric-chahin authored
View
9 activerecord/lib/active_record/associations/association_scope.rb
@@ -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
View
5 activerecord/lib/active_record/reflection.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.