aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2014-06-10 16:13:23 -0400
committereileencodes <eileencodes@gmail.com>2014-06-10 22:08:50 -0400
commit5823e429981dc74f8f53187d2ab573823381bf28 (patch)
treebcf100f4342626fe8e463404e9a114736211d733 /activerecord/lib/active_record/associations
parenta5ab38c7bb99e135e29f5727e3e75a1e562d8216 (diff)
downloadrails-5823e429981dc74f8f53187d2ab573823381bf28.tar.gz
rails-5823e429981dc74f8f53187d2ab573823381bf28.tar.bz2
rails-5823e429981dc74f8f53187d2ab573823381bf28.zip
begin refactoring add_constraints by moving join keys
add_constraints is complicated and difficult to read. This is the beginning of a long process of refactoring this code. First step: moved the join keys out of AssociationScope and into reflection. We then don't need to call `reflection` because now reflection is `self`. `foreign_key` must be named something else because reflection already has a `foreign_key` method and when passed into `JoinKeys` it was getting the wrong assignment. `reflection_foreign_key` seemed to be an appropriate name. I also named `key` `reflection_key` to match `reflection_foreign_key`.
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/association_scope.rb15
1 files changed, 3 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb
index 31108cc1aa..519d4d8651 100644
--- a/activerecord/lib/active_record/associations/association_scope.rb
+++ b/activerecord/lib/active_record/associations/association_scope.rb
@@ -105,18 +105,9 @@ module ActiveRecord
chain.each_with_index do |reflection, i|
table, foreign_table = tables.shift, tables.first
- if reflection.source_macro == :belongs_to
- if reflection.polymorphic?
- key = reflection.association_primary_key(assoc_klass)
- else
- key = reflection.association_primary_key
- end
-
- foreign_key = reflection.foreign_key
- else
- key = reflection.foreign_key
- foreign_key = reflection.active_record_primary_key
- end
+ join_keys = reflection.join_keys(assoc_klass)
+ key = join_keys.key
+ foreign_key = join_keys.foreign_key
if reflection == chain.last
bind_val = bind scope, table.table_name, key.to_s, owner[foreign_key], tracker