Class: Surus::JSON::HasAndBelongsToManyScopeBuilder
Instance Attribute Summary
#association, #outside_scope
Instance Method Summary
collapse
#conditions, #initialize, #order, #outside_class
Instance Method Details
#association_foreign_key ⇒ Object
17
18
19
|
# File 'lib/surus/json/has_and_belongs_to_many_scope_builder.rb', line 17
def association_foreign_key
connection.quote_column_name association.association_foreign_key
end
|
#association_primary_key ⇒ Object
29
30
31
|
# File 'lib/surus/json/has_and_belongs_to_many_scope_builder.rb', line 29
def association_primary_key
connection.quote_column_name association.association_primary_key
end
|
#association_table ⇒ Object
25
26
27
|
# File 'lib/surus/json/has_and_belongs_to_many_scope_builder.rb', line 25
def association_table
connection.quote_table_name association.klass.table_name
end
|
#foreign_key ⇒ Object
21
22
23
|
# File 'lib/surus/json/has_and_belongs_to_many_scope_builder.rb', line 21
def foreign_key
connection.quote_column_name association.foreign_key
end
|
#join_table ⇒ Object
13
14
15
|
# File 'lib/surus/json/has_and_belongs_to_many_scope_builder.rb', line 13
def join_table
connection.quote_table_name association.join_table
end
|
#scope ⇒ Object
4
5
6
7
8
9
10
11
|
# File 'lib/surus/json/has_and_belongs_to_many_scope_builder.rb', line 4
def scope
s = association
.klass
.joins("JOIN #{join_table} ON #{join_table}.#{association_foreign_key}=#{association_table}.#{association_primary_key}")
.where("#{outside_class.quoted_table_name}.#{association_primary_key}=#{join_table}.#{foreign_key}")
s = s.instance_eval(&association.scope) if association.scope
s
end
|