Method: OccamsRecord::EagerLoaders::Builder#eager_load
- Defined in:
- lib/occams-record/eager_loaders/builder.rb
#eager_load(assoc, scope = nil, select: nil, use: nil, as: nil, from: nil, optimizer: :select, active_record_fallback: nil) { ... } ⇒ Object
Specify an association to be eager-loaded. For maximum memory savings, only SELECT the colums you actually need.
If you pass a block to nest more eager loads, you may call it with one of two forms: with an argument and without:
If you ommit the block argument, the “self” inside the block will be the eager loader. You can call “eager_load” and “scope” directly.
If you include the block argument, the “self” inside the block is the same as the self outside the block. The argument will be the eager loader, which you can use to make additional “eager_load” or “scope” calls.
ActiveRecord::Relation on which you may call all the normal query hethods (select, where, etc) as well as any scopes you’ve defined on the model.
31 32 33 34 |
# File 'lib/occams-record/eager_loaders/builder.rb', line 31 def eager_load(assoc, scope = nil, select: nil, use: nil, as: nil, from: nil, optimizer: :select, active_record_fallback: nil, &builder) @eager_loaders.add(assoc, scope, select: select, use: use, as: as, from: from, optimizer: optimizer, active_record_fallback: active_record_fallback, &builder) self end |