Class: Surus::JSON::BelongsToScopeBuilder

Inherits:
AssociationScopeBuilder show all
Defined in:
lib/surus/json/belongs_to_scope_builder.rb

Instance Attribute Summary

Attributes inherited from AssociationScopeBuilder

#association, #outside_scope

Instance Method Summary collapse

Methods inherited from AssociationScopeBuilder

#conditions, #initialize, #order, #outside_class

Constructor Details

This class inherits a constructor from Surus::JSON::AssociationScopeBuilder

Instance Method Details

#association_foreign_keyObject



16
17
18
# File 'lib/surus/json/belongs_to_scope_builder.rb', line 16

def association_foreign_key
  "#{quote_table_name outside_class.table_name}.#{quote_column_name association.foreign_key}"
end

#association_primary_keyObject



12
13
14
# File 'lib/surus/json/belongs_to_scope_builder.rb', line 12

def association_primary_key
  "#{quote_table_name association.table_name}.#{quote_column_name association.active_record_primary_key}"
end

#scopeObject



4
5
6
7
8
9
10
# File 'lib/surus/json/belongs_to_scope_builder.rb', line 4

def scope
  s = association
    .klass
    .where("#{association_primary_key}=#{association_foreign_key}")
  s = s.instance_eval(&association.scope) if association.scope
  s
end