martenframework / marten

The pragmatic web framework.
https://martenframework.com
MIT License
425 stars 24 forks source link

Make it possible to specify a custom query set when prefetching records #264

Open ellmetha opened 2 months ago

ellmetha commented 2 months ago

Description

Let's make it possible to configure a custom query set to use when prefetching records.

Context

In some situations, it may be necessary to ensure that records are prefetched using a specific query set. This would be the case when:

Proposition

To allow for that, let's introduce an alternative version of the #prefetch method that takes a single relation name as input and an optional query set object:

List.prefetch(:items, query_set: Item.order(:position))

The configured prefetch operation should take into account the specified query set if one is specified; otherwise, the default one should be used. Special care should be taken to ensure that the type of the query set type is consistent with the specified relation.