aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2014-07-29 13:56:39 -0400
committereileencodes <eileencodes@gmail.com>2014-07-31 11:07:25 -0400
commit377bece684715edd802ad73fee739669d15eafa6 (patch)
tree37ed45a35bcbcf1c0f9f4607ea01a66010c9dde7 /activerecord/lib/active_record/associations
parent84093c662770893ad840c36f2b99204593d4a7de (diff)
downloadrails-377bece684715edd802ad73fee739669d15eafa6.tar.gz
rails-377bece684715edd802ad73fee739669d15eafa6.tar.bz2
rails-377bece684715edd802ad73fee739669d15eafa6.zip
Refactor join_keys to remove complex conditionals
Pushing conditionals down to through reflection Only the through association needs the part of this conditional that deals with belongs to and polymorphic? so that can be pushed down into the ThroughReflection reducing the conditionals. Remove conditional because we can delegate join keys to source reflection Remove need for source_macro checking By adding join_id_for to the other reflections we remove the need to cehck against the source_macro and can reduce the conditioanl from the original join_id_for(owner) Using polymorphism instead of testing the source_macro This case statement in join_association is almost exactly the same as the original join_keys code. Testing taht theory by creating a new join_dependency_keys(assoc_klass) method. Refactor join_keys further to be more concise Fixed format of "#:nodoc:" to "# :nodoc:" where I added them to this file.
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_association.rb11
1 files changed, 3 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
index 719eff9acc..a9d1099871 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -37,14 +37,9 @@ module ActiveRecord
table = tables.shift
klass = reflection.klass
- case reflection.source_macro
- when :belongs_to
- key = reflection.association_primary_key
- foreign_key = reflection.foreign_key
- else
- key = reflection.foreign_key
- foreign_key = reflection.active_record_primary_key
- end
+ join_keys = reflection.join_keys(klass)
+ key = join_keys.key
+ foreign_key = join_keys.foreign_key
constraint = build_constraint(klass, table, key, foreign_table, foreign_key)