Module: EagerRecord::ScopedPreloading::AssociationCollectionExtensions

Defined in:
lib/eager_record/scoped_preloading.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



31
32
33
# File 'lib/eager_record/scoped_preloading.rb', line 31

def self.included(base)
  base.module_eval { alias_method_chain :find, :scoped_preloading }
end

Instance Method Details

#current_scoped_methodsObject

Because of some likely unintentional plumbing in the scoping/association delegation chain, current_scoped_methods returns an association proxy’s scope when called on the association collection. This means that, among other things, a named scope called on an association collection will duplicate the association collection’s SQL restriction.



41
42
43
# File 'lib/eager_record/scoped_preloading.rb', line 41

def current_scoped_methods
  @reflection.klass.__send__(:current_scoped_methods)
end

#find_using_scoped_preload(originating_collection, *args) ⇒ Object



53
54
55
# File 'lib/eager_record/scoped_preloading.rb', line 53

def find_using_scoped_preload(originating_collection, *args)
  find_without_scoped_preloading(*args)
end

#find_with_scoped_preloading(*args) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/eager_record/scoped_preloading.rb', line 45

def find_with_scoped_preloading(*args)
  if originating_collection = @owner.instance_variable_get(:@originating_collection)
    find_using_scoped_preload(originating_collection, *args)
  else
    find_without_scoped_preloading(*args)
  end
end