NAME
Mojolicious::Plugin::Fondation::Model::DBIx::Async::ResultSet - Fondation ResultSet — with() for fluent prefetch (many_to_many + has_many)
VERSION
version 0.03
SYNOPSIS
# many_to_many
$c->model('user')->with('groups')->all;
# has_many
$c->model('user')->with('orders')->all;
# both at once — single query
$c->model('user')->with('groups', 'orders')->all;
# chained with search
$c->model('user')->with('groups')->search({ active => 1 })->all;
# find() with prefetch — single query, returns row or undef
$c->model('user')->with('groups')->find($id);
DESCRIPTION
Mojolicious::Plugin::Fondation::Model::DBIx::Async::ResultSet extends DBIx::Class::Async::ResultSet with a with() method that declares relationships to prefetch. The all() and find() overrides delegate to search_with_prefetch, ensuring a single query with all nested data.
with() accepts one or more relationship names:
many_to_many — discovered via the
_fondation_many_to_manypackage hash populated by DBIx::Class::Relationship::ManyToMany::Async. Stored as{ pivot => target }in the prefetch hash.has_many — discovered via "has_relationship" in DBIx::Class::ResultSource with
accessor eq 'multi'. Stored as{ relation => undef }, meaning direct prefetch without nesting.belongs_to / might_have — rejected with a clear error. These single-accessor relationships don't need prefetch (they're resolved via a simple foreign key lookup).
When the same key appears in both many_to_many and has_many (e.g. with('groups', 'user_group') where both resolve to the user_group pivot), the many_to_many value wins (//= guard), since its nested prefetch already includes the has_many data.
The search() override propagates the prefetch metadata to the new ResultSet, so chaining with(...)-search({...})->all> works correctly.
The model helper in Mojolicious::Plugin::Fondation::Model::DBIx::Async re-blesses every ResultSet into this class, making with() available on all $c->model(...) calls.
NAME
Mojolicious::Plugin::Fondation::Model::DBIx::Async::ResultSet — fluent prefetch for DBIx::Class::Async
METHODS
with
$rs = $rs->with(@relation_names);
Stores prefetch metadata on the ResultSet. Does not execute a query. Returns $self for chaining.
all
my $rows = $schema->await($rs->with('groups')->all);
If with() was called, delegates to search_with_prefetch for a single-query prefetch. Otherwise falls back to the standard "all" in DBIx::Class::Async::ResultSet.
find
my $row = $schema->await($rs->with('groups')->find($id));
If with() was called, uses search_with_prefetch with a qualified primary-key condition (me.id) for a single-query lookup. Returns the first row or undef. Falls back to the standard find() for multi-column primary keys.
search
my $new_rs = $rs->with('groups')->search({ active => 1 });
Returns a new ResultSet (same class) with the prefetch metadata copied. Subsequent all() or find() will use the prefetch.
SEE ALSO
Mojolicious::Plugin::Fondation::Model::DBIx::Async, DBIx::Class::Async::ResultSet, DBIx::Class::Relationship::ManyToMany::Async
AUTHOR
Daniel Brosseau <dab@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by Daniel Brosseau.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.