Class: DatastaxRails::Associations::AssociationScope

Inherits:
Object
  • Object
show all
Defined in:
lib/datastax_rails/associations/association_scope.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(association) ⇒ AssociationScope

Returns a new instance of AssociationScope.



9
10
11
# File 'lib/datastax_rails/associations/association_scope.rb', line 9

def initialize(association)
  @association = association
end

Instance Attribute Details

#associationObject (readonly)

Returns the value of attribute association.



4
5
6
# File 'lib/datastax_rails/associations/association_scope.rb', line 4

def association
  @association
end

Instance Method Details

#scopeObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/datastax_rails/associations/association_scope.rb', line 13

def scope
  scope = klass.unscoped
  scope = scope.extending(*Array.wrap(options[:extend]))

  if reflection.source_macro == :belongs_to
    scope.where('id' => owner.send(reflection.foreign_key))
  else
    scope.where(reflection.foreign_key => owner.id)
  end
end