class NinjaModel::Associations::AssociationScope

Attributes

association[R]

Public Class Methods

new(association) click to toggle source
# File lib/ninja_model/associations/association_scope.rb, line 10
def initialize(association)
  @association = association
end

Public Instance Methods

add_constraints(scope) click to toggle source
# 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() click to toggle source
# File lib/ninja_model/associations/association_scope.rb, line 14
def scope
  scope = klass.unscoped
  scope = scope.extending(*Array.wrap(options[:extend]))
  scope = scope.apply_finder_options(
    options.slice(
      :order, :limit, :joins, :group, :having, :offset
    )
  )

  add_constraints(scope)
end