Class: DatastaxRails::Associations::AssociationScope
- Defined in:
- lib/datastax_rails/associations/association_scope.rb
Overview
Creates the scope (relation) for the assocation
Instance Attribute Summary collapse
-
#association ⇒ Object
readonly
Returns the value of attribute association.
Instance Method Summary collapse
-
#initialize(association) ⇒ AssociationScope
constructor
A new instance of AssociationScope.
- #scope ⇒ Object
Constructor Details
#initialize(association) ⇒ AssociationScope
Returns a new instance of AssociationScope.
10 11 12 |
# File 'lib/datastax_rails/associations/association_scope.rb', line 10 def initialize(association) @association = association end |
Instance Attribute Details
#association ⇒ Object (readonly)
Returns the value of attribute association.
5 6 7 |
# File 'lib/datastax_rails/associations/association_scope.rb', line 5 def association @association end |
Instance Method Details
#scope ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/datastax_rails/associations/association_scope.rb', line 14 def scope scope = klass.unscoped scope = scope.extending(*Array.wrap([: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 |