Module: Goldiloader::CollectionProxyPatch

Defined in:
lib/goldiloader/active_record_patches.rb

Instance Method Summary collapse

Instance Method Details

#exists?(*args) ⇒ Boolean

The CollectionProxy just forwards exists? to the underlying scope so we need to intercept this and force it to use size which handles fully_load properly.

Returns:

  • (Boolean)


202
203
204
205
206
207
208
209
210
211
# File 'lib/goldiloader/active_record_patches.rb', line 202

def exists?(*args)
  # We don't fully_load the association when arguments are passed to exists? since Rails always
  # pushes this query into the database without any caching (and it likely not a common
  # scenario worth optimizing).
  if args.empty? && @association.fully_load?
    size > 0
  else
    scope.exists?(*args)
  end
end