[Dbix-class] Fixing my relationships to get working queries
Peter Rabbitson
rabbit+dbic at rabbit.us
Mon Jan 19 18:47:19 GMT 2015
On 01/19/2015 07:23 PM, John Stoffel wrote:
> For my perl code, to get the same result, I was trying to use the
> following perl code, which removes a bunch of setup code to make it
> smaller:
>
> my $rs = $schema->resultset('Name')->search({ full_name =>
> { regexp => '[[:<:]]'.$name.'[[:>:]]' }
> },
> {
> prefetch => [ 'account' ],
> rows => 10,
> order_by => { -asc => 'full_name' },
> });
Ok, so DBIC did run one statement, you are simply unhappy about the
subquery. Given you are focused on what DBIC does, the easiest way to
explain it would be for you to remove the 'rows => 10' above, and to
re-run the query and observe the trace.
Realize that the '10' applies to the amount of Names, not to the amount
of "Names + unknown number of Accounts per name".
If you can come up with a more efficient way to ask a RDBMS for "first N
things, and *all* their related things (a not-beforehand-known amount
for each individual thing of the N things) - please share, as it would
be of great interest to me.
Cheers
More information about the DBIx-Class
mailing list