[Dbix-class] "rows" count reflects wrong table when "prefetch" is used
Matt S Trout
dbix-class at trout.me.uk
Thu Jul 20 02:03:01 CEST 2006
apv wrote:
> I must say DBIC is really nice. I had problems migrating to it a few
> months ago b/c things were in flux (Schema's were just entering and
> doc-cupboard was a bit bare) so left it alone for awhile. I'm back at
> it and I was able to replace some CDBI classes in just a few minutes
> yesterday.
>
> I think I've found a problem though I might be using things wrong.
> (Within a Catalyst app) I have a table of "word"s which own
> "definition"s. Using this, I get back exactly 10 _words_ with
> definitions.
>
> $c->model("DB::word")
> ->search({
> word => { "like", "$letter\%" },
> active => "yes",
> },
> {
> rows => 10,
> order_by => "word",
> page => $page,
> }
> )
>
> But using this prefetch, I get back 10 _definitions_ with however
> many words they belong(s)_to. Too few words are returned almost every
> time.
>
> $c->model("DB::word")
> ->search({
> word => { "like", "$letter\%" },
> active => "yes",
> },
> {
> rows => 10,
> prefetch => [qw/definitions/],
> order_by => "word",
> page => $page,
> }
> )
>
> I think it should still return 10 words with however many definitions
> each owns, right? Or am I using the prefetch incorrectly? It's mysql
> if it matters.
As soon as you prefetch a has_many we've got no effective way to handle the
limit/offset as yet; "needs subselects, hopefully in 08"
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
More information about the Dbix-class
mailing list