There's more than one way to do things | |
PerlMonks |
Re: DBIx::Class - Count with prefetch creates nested queryby Myrddin Wyllt (Hermit) |
on Jul 06, 2015 at 18:09 UTC ( [id://1133406]=note: print w/replies, xml ) | Need Help?? |
I think the sub-select is in there because you prefetch 'rma'. You are not using it in the 'where' clause, so it is pretty much superfluous to the returned value; you are going to get a count of all 'shipment' records whether or not they have any associated 'rma' records. If that's what you want, just re-write the query as :
Which gives the obvious SELECT COUNT( * ) FROM shipment meIf you need a count of all shipments which have at least one 'rma' record, you need to re-write your query as:
Which gives SQL of:
I think DBIC puts the sub-select in your case because it expects the 'rma' prefetch to be used in the 'where' clause, and thinks it will be using a LEFT JOIN (which isn't unreasonable).
In Section
Seekers of Perl Wisdom
|
|