[Dbix-class] "rows" count reflects wrong table when "prefetch" is used

apv apv at sedition.com
Thu Jul 20 01:00:11 CEST 2006


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.


–Ashley




More information about the Dbix-class mailing list