module Switchman::ActiveRecord::Reflection::AssociationScopeCache
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/switchman/active_record/reflection.rb, line 18 def initialize(*args) super # on ThroughReflection, these won't be initialized (cause it doesn't # inherit from AssociationReflection), so make sure they're # initialized here @association_scope_cache ||= {} @scope_lock ||= Mutex.new end
Public Instance Methods
association_scope_cache(klass, owner, &block)
click to toggle source
cache association scopes by shard. this technically belongs on AssociationReflection
, but we put it on ThroughReflection as well, instead of delegating to its internal HasManyAssociation, losing its proper `klass`
# File lib/switchman/active_record/reflection.rb, line 31 def association_scope_cache(klass, owner, &block) key = self key = [key, owner._read_attribute(@foreign_type)] if polymorphic? key = [key, shard(owner).id].flatten klass.cached_find_by_statement(key, &block) end