module Goldiloader::ThroughAssociationPatch
Public Instance Methods
auto_include?()
click to toggle source
Calls superclass method
# File lib/goldiloader/active_record_patches.rb, line 181 def auto_include? # Only auto include through associations if the target association is auto-loadable through_association = owner.association(through_reflection.name) auto_include_self = super # If the current association cannot be auto-included there is nothing we can do return false unless auto_include_self # If the through association can just be auto-included we're good return true if through_association.auto_include? # If the through association was already loaded and does not contain new, changed, or destroyed records # we are also able to auto-include the association. It means it has only already been read or changes are # already persisted. through_association.loaded? && Array.wrap(through_association.target).none? do |record| record.new_record? || record.changed? || record.destroyed? end end