diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-04-13 00:15:24 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-04-14 19:34:19 +0100 |
commit | 6b6ecbefad648f39b507dbb59c9d22ff9031f7a8 (patch) | |
tree | 5ff73b59996aa8831b8f9e374ebd9a1f666cf036 | |
parent | cd233dd87e6f0f9113a397531d37075cfa7c6526 (diff) | |
download | rails-6b6ecbefad648f39b507dbb59c9d22ff9031f7a8.tar.gz rails-6b6ecbefad648f39b507dbb59c9d22ff9031f7a8.tar.bz2 rails-6b6ecbefad648f39b507dbb59c9d22ff9031f7a8.zip |
Extract the constraint-building for joins in JoinAssociation into a separate method to make it easy to change/override (requested by Ernie Miller so that MetaWhere can add to it easily)
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency/join_association.rb | 22 |
1 files changed, 14 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 4121a5b378..0a666598ed 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -89,14 +89,7 @@ module ActiveRecord foreign_key = reflection.active_record_primary_key end - constraint = table[key].eq(foreign_table[foreign_key]) - - if reflection.klass.finder_needs_type_condition? - constraint = table.create_and([ - constraint, - reflection.klass.send(:type_condition, table) - ]) - end + constraint = build_constraint(reflection, table, key, foreign_table, foreign_key) relation.from(join(table, constraint)) @@ -111,6 +104,19 @@ module ActiveRecord relation end + def build_constraint(reflection, table, key, foreign_table, foreign_key) + constraint = table[key].eq(foreign_table[foreign_key]) + + if reflection.klass.finder_needs_type_condition? + constraint = table.create_and([ + constraint, + reflection.klass.send(:type_condition, table) + ]) + end + + constraint + end + def join_relation(joining_relation) self.join_type = Arel::OuterJoin joining_relation.joins(self) |