Class: ActiveSimilar::Association
- Inherits:
-
Object
- Object
- ActiveSimilar::Association
- Defined in:
- lib/active_similar/association.rb
Overview
Builds association subquery.
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#other ⇒ Object
readonly
Returns the value of attribute other.
-
#reflection ⇒ Object
readonly
Returns the value of attribute reflection.
Instance Method Summary collapse
-
#initialize(name, klass, other) ⇒ Association
constructor
Returns a new instance of Association.
-
#scope ⇒ ActiveRecord::Relation
Returns the association join scope.
Constructor Details
#initialize(name, klass, other) ⇒ Association
Returns a new instance of Association.
20 21 22 23 24 |
# File 'lib/active_similar/association.rb', line 20 def initialize(name, klass, other) @klass = klass @reflection = klass.reflect_on_association(name) @other = other end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
6 7 8 |
# File 'lib/active_similar/association.rb', line 6 def klass @klass end |
#other ⇒ Object (readonly)
Returns the value of attribute other.
6 7 8 |
# File 'lib/active_similar/association.rb', line 6 def other @other end |
#reflection ⇒ Object (readonly)
Returns the value of attribute reflection.
6 7 8 |
# File 'lib/active_similar/association.rb', line 6 def reflection @reflection end |
Instance Method Details
#scope ⇒ ActiveRecord::Relation
Returns the association join scope.
28 29 30 31 32 |
# File 'lib/active_similar/association.rb', line 28 def scope klass .joins(through_name) .where(through_table_name => { foreign_key => subquery }) end |