Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 56 lines (46 sloc) 1.607 kb
e18679a @jonleighton Abstract some common code from AssociationScope and JoinDependency::Join...
jonleighton authored
1 module ActiveRecord
2 module Associations
3 # Helper class module which gets mixed into JoinDependency::JoinAssociation and AssociationScope
4 module JoinHelper #:nodoc:
5
6 def join_type
7 Arel::InnerJoin
8 end
9
10 private
11
12 def construct_tables
13 tables = []
14 chain.each do |reflection|
15 tables << alias_tracker.aliased_table_for(
16 table_name_for(reflection),
17 table_alias_for(reflection, reflection != self.reflection)
18 )
19
20 if reflection.source_macro == :has_and_belongs_to_many
21 tables << alias_tracker.aliased_table_for(
22 (reflection.source_reflection || reflection).options[:join_table],
23 table_alias_for(reflection, true)
24 )
25 end
26 end
27 tables
28 end
29
30 def table_name_for(reflection)
31 reflection.table_name
32 end
33
34 def table_alias_for(reflection, join = false)
36d289a @tenderlove a few minor performance improvements: fewer strings, fewer range objects...
tenderlove authored
35 name = "#{reflection.plural_name}_#{alias_suffix}"
e18679a @jonleighton Abstract some common code from AssociationScope and JoinDependency::Join...
jonleighton authored
36 name << "_join" if join
37 name
38 end
39
37d93ea @jonleighton Fix tests under postgres - we should always put conditions in the WHERE ...
jonleighton authored
40 def join(table, constraint)
41 table.create_join(table, table.create_on(constraint), join_type)
e18679a @jonleighton Abstract some common code from AssociationScope and JoinDependency::Join...
jonleighton authored
42 end
43
37d93ea @jonleighton Fix tests under postgres - we should always put conditions in the WHERE ...
jonleighton authored
44 def sanitize(conditions, table)
e18679a @jonleighton Abstract some common code from AssociationScope and JoinDependency::Join...
jonleighton authored
45 conditions = conditions.map do |condition|
46 condition = active_record.send(:sanitize_sql, interpolate(condition), table.table_alias || table.name)
47 condition = Arel.sql(condition) unless condition.is_a?(Arel::Node)
48 condition
49 end
50
51 conditions.length == 1 ? conditions.first : Arel::Nodes::And.new(conditions)
52 end
53 end
54 end
55 end
Something went wrong with that request. Please try again.