Module: Quo::Preloadable
- Defined in:
- lib/quo/preloadable.rb,
sig/generated/quo/preloadable.rbs
Overview
Mixin for adding preload/includes support to collection-backed queries
Class Method Summary collapse
Instance Method Summary collapse
-
#includes(*options) ⇒ Quo::Query
Alias for
preload. -
#preload(*options) ⇒ Quo::Query
For use with collections of ActiveRecord models.
- #preload_includes(records, preload = nil) ⇒ Object
-
#query ⇒ Object & Enumerable[untyped]
This implementation of
querycallscollectionand preloads the includes.
Class Method Details
.included(base) ⇒ Object
8 9 10 |
# File 'lib/quo/preloadable.rb', line 8 def self.included(base) base.prop :_rel_preload, base._Nilable(base._Any), reader: false, writer: false end |
Instance Method Details
#includes(*options) ⇒ Quo::Query
Alias for preload
31 32 33 |
# File 'lib/quo/preloadable.rb', line 31 def includes(*) preload(*) end |
#preload(*options) ⇒ Quo::Query
For use with collections of ActiveRecord models. Configures ActiveRecord::Associations::Preloader to load associations of models in the collection
24 25 26 |
# File 'lib/quo/preloadable.rb', line 24 def preload(*) copy(_rel_preload: ) end |
#preload_includes(records, preload = nil) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/quo/preloadable.rb', line 40 def preload_includes(records, preload = nil) ::ActiveRecord::Associations::Preloader.new( records: records, associations: preload || @_rel_preload ).call end |
#query ⇒ Object & Enumerable[untyped]
This implementation of query calls collection and preloads the includes.
14 15 16 17 18 |
# File 'lib/quo/preloadable.rb', line 14 def query records = collection preload_includes(records) if @_rel_preload records end |