diff options
author | Eric Chahin <erc73@cornell.edu> | 2014-05-05 16:03:29 -0400 |
---|---|---|
committer | Eric Chahin <erc73@cornell.edu> | 2014-05-05 17:42:14 -0400 |
commit | bf4a80223b77d84ad158fcc057eef13327773aa2 (patch) | |
tree | 5402f3217c4482944ac797bf7550b33aeb1e52ef | |
parent | 4efb0f373047c44249bc6542fdf9969e4c63dd88 (diff) | |
download | rails-bf4a80223b77d84ad158fcc057eef13327773aa2.tar.gz rails-bf4a80223b77d84ad158fcc057eef13327773aa2.tar.bz2 rails-bf4a80223b77d84ad158fcc057eef13327773aa2.zip |
Refactor AssociationScope#get_bind_values
Added #join_id_for(owner) to reflection to avoid accessing the source_macro
-rw-r--r-- | activerecord/lib/active_record/associations/association_scope.rb | 9 | ||||
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 5 |
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 |