Class: Surus::JSON::HasManyThroughScopeBuilder
Instance Attribute Summary
#association, #outside_scope
Instance Method Summary
collapse
#conditions, #initialize, #order, #outside_class
Instance Method Details
#association_primary_key ⇒ Object
64
65
66
|
# File 'lib/surus/json/has_many_through_scope_builder.rb', line 64
def association_primary_key
quote_column_name association.association_primary_key
end
|
#association_table ⇒ Object
60
61
62
|
# File 'lib/surus/json/has_many_through_scope_builder.rb', line 60
def association_table
quote_table_name association.klass.table_name
end
|
#foreign_key ⇒ Object
40
41
42
|
# File 'lib/surus/json/has_many_through_scope_builder.rb', line 40
def foreign_key
quote_column_name association.foreign_key
end
|
#join_through_table_foreign_key_on_association ⇒ Object
24
25
26
|
# File 'lib/surus/json/has_many_through_scope_builder.rb', line 24
def join_through_table_foreign_key_on_association
"JOIN #{through_table} ON #{through_table}.#{through_primary_key}=#{association_table}.#{foreign_key}"
end
|
#join_through_table_foreign_key_on_through ⇒ Object
28
29
30
|
# File 'lib/surus/json/has_many_through_scope_builder.rb', line 28
def join_through_table_foreign_key_on_through
"JOIN #{through_table} ON #{through_table}.#{foreign_key}=#{association_table}.#{association_primary_key}"
end
|
#outside_primary_key ⇒ Object
36
37
38
|
# File 'lib/surus/json/has_many_through_scope_builder.rb', line 36
def outside_primary_key
quote_column_name outside_class.primary_key
end
|
#outside_table ⇒ Object
32
33
34
|
# File 'lib/surus/json/has_many_through_scope_builder.rb', line 32
def outside_table
quote_table_name outside_class.table_name
end
|
#scope ⇒ Object
4
5
6
7
8
9
10
11
12
|
# File 'lib/surus/json/has_many_through_scope_builder.rb', line 4
def scope
s = association
.klass
.joins(through_table_join)
.where("#{through_table}.#{through_foreign_key}=#{outside_table}.#{outside_primary_key}")
s = s.instance_eval(&association.scope) if association.scope
s
end
|
#through_association_foreign_key ⇒ Object
56
57
58
|
# File 'lib/surus/json/has_many_through_scope_builder.rb', line 56
def through_association_foreign_key
quote_column_name through_reflection.association_foreign_key
end
|
#through_foreign_key ⇒ Object
52
53
54
|
# File 'lib/surus/json/has_many_through_scope_builder.rb', line 52
def through_foreign_key
quote_column_name through_reflection.foreign_key
end
|
#through_primary_key ⇒ Object
48
49
50
|
# File 'lib/surus/json/has_many_through_scope_builder.rb', line 48
def through_primary_key
quote_column_name through_reflection.active_record_primary_key
end
|
#through_table ⇒ Object
44
45
46
|
# File 'lib/surus/json/has_many_through_scope_builder.rb', line 44
def through_table
quote_table_name through_reflection.table_name
end
|
#through_table_join ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/surus/json/has_many_through_scope_builder.rb', line 16
def through_table_join
if foreign_key == through_association_foreign_key
join_through_table_foreign_key_on_association
else
join_through_table_foreign_key_on_through
end
end
|