Class: NinjaModel::Associations::AssociationScope
- Inherits:
-
Object
- Object
- NinjaModel::Associations::AssociationScope
- Defined in:
- lib/ninja_model/associations/association_scope.rb
Instance Attribute Summary collapse
-
#association ⇒ Object
readonly
Returns the value of attribute association.
Instance Method Summary collapse
- #add_constraints(scope) ⇒ Object
-
#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/ninja_model/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/ninja_model/associations/association_scope.rb', line 5 def association @association end |
Instance Method Details
#add_constraints(scope) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ninja_model/associations/association_scope.rb', line 26 def add_constraints(scope) if reflection.source_macro == :belongs_to key = reflection.association_primary_key foreign_key = reflection.foreign_key else key = reflection.foreign_key foreign_key = reflection.active_record_primary_key end scope = scope.where(key => owner[foreign_key]) end |
#scope ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ninja_model/associations/association_scope.rb', line 14 def scope scope = klass.unscoped scope = scope.extending(*Array.wrap([:extend])) scope = scope.( .slice( :order, :limit, :joins, :group, :having, :offset ) ) add_constraints(scope) end |