class Marten::DB::Query::Prefetcher

Overview

The main prefetcher class.

A prefetcher is responsible for prefetching relation recordss for the records matched by a given query set. This allows to avoid N+1 queries problems for relation fields (and reverse relations) that map to multiple records.

A prefetcher is initialized with an array of records, an array of relation strings to prefetch, and an the identifier of the database to use for the prefetching queries. The prefetcher decorates the records with the prefetched records, and also caches the prefetched records for future use.

Defined in:

marten/db/query/prefetcher.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(records : Array(Model), relations : Array(String), using : String | Nil) #

[View source]

Instance Method Detail

def execute : Nil #

[View source]