aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-06 15:35:33 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-06 15:35:33 -0300
commitd97581921b0ff7a31ce63fef4687437594f38447 (patch)
treeb969d82de4aec7c8ad8d3d6291a385c697307f70 /activerecord
parent2bb008a6cfa5ddfc4442fe7ec979e4861c9f4e09 (diff)
parentbf4a80223b77d84ad158fcc057eef13327773aa2 (diff)
downloadrails-d97581921b0ff7a31ce63fef4687437594f38447.tar.gz
rails-d97581921b0ff7a31ce63fef4687437594f38447.tar.bz2
rails-d97581921b0ff7a31ce63fef4687437594f38447.zip
Merge pull request #14982 from eric-chahin/GBV_refactor
Refactored AssociationScope#get_bind_values
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/association_scope.rb9
-rw-r--r--activerecord/lib/active_record/reflection.rb5
2 files changed, 6 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb
index f1a3b23d5a..572f556999 100644
--- a/activerecord/lib/active_record/associations/association_scope.rb
+++ b/activerecord/lib/active_record/associations/association_scope.rb
@@ -47,15 +47,8 @@ module ActiveRecord
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
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 95485ddada..7f4d77849a 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -278,6 +278,11 @@ module ActiveRecord
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