On Sun, 27 Jul 2008, Moritz Onken wrote:



Hi Moritz,

Nope, you're misunderstanding how it works.

Search with prefetch fetches data and stores it in the resultset when next/all are called on the resultset.

However find() doesnt use prefetched data at all, there is no caching for find.

$rs->first, doesnt run any extra queries. Since that's now not part of the resultset any more, any rels called on the result of first() also produce more queries.

In short, it only works on chained resultset objects.

Jess


Thanks, that makes sense. But I recognized that the test case didn't exactly show
where my problem is. I edited the test:

my @rs =
$schema->resultset("Complex")
->search( undef, { prefetch => { parents => "parent" } } );
for (@rs) {
        is( defined $_->parents->first->parent->id, 1 );
}


As I attempted to explain (but likely failed). It only works across chained resultsets..

When you call ->first, you produce a row object, not a resultset. That row object is now standalone, not attached to the resultset that did the search/caching.. Therefore calling any related methods on it (eg "parent") will produce a new query.

Jess


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[EMAIL PROTECTED]

Reply via email to