class ActiveAny::Associations::AssociationScope

Constants

INSTANCE

Public Class Methods

create() click to toggle source
# File lib/active_any/associations/association_scope.rb, line 10
def self.create
  new
end
scope(association) click to toggle source
# File lib/active_any/associations/association_scope.rb, line 6
def self.scope(association)
  INSTANCE.scope(association)
end

Public Instance Methods

scope(association) click to toggle source
# File lib/active_any/associations/association_scope.rb, line 16
def scope(association)
  klass = association.klass
  reflection = association.reflection
  scope = klass.all
  owner = association.owner

  add_constraints(scope, owner, reflection)
end

Private Instance Methods

add_constraints(scope, owner, reflection) click to toggle source
# File lib/active_any/associations/association_scope.rb, line 27
def add_constraints(scope, owner, reflection)
  join_keys = reflection.join_keys
  key = join_keys.key
  value = owner.send(join_keys.foreign_key)
  scope.where(key => value)
end