Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extract the constraint-building for joins in JoinAssociation into a s…

…eparate method to make it easy to change/override (requested by Ernie Miller so that MetaWhere can add to it easily)
  • Loading branch information...
commit 6b6ecbefad648f39b507dbb59c9d22ff9031f7a8 1 parent cd233dd
@jonleighton jonleighton authored
View
22 activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -89,14 +89,7 @@ def join_to(relation)
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 @@ def join_to(relation)
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)
Please sign in to comment.
Something went wrong with that request. Please try again.