[Dbix-class] Prefetch multi bug (test included)

Matt S Trout dbix-class at trout.me.uk
Sat Apr 19 17:13:30 BST 2008


On Fri, Apr 18, 2008 at 02:11:05PM +0200, Peter Rabbitson wrote:
> When specifying a prefetch which first converges to a belongs_to and then 
> fans out to multiple has_many's, the collapse code does not work. Attached 
> is a test against 08 trunk.

No, it doesn't. That's been a known limitation for some time.

Please submit this either as a TODO test or as a test to ensure an exception
is thrown when a situation the code can't handle is reached.

> Index: t/76joins.t
> ===================================================================
> --- t/76joins.t	(revision 4274)
> +++ t/76joins.t	(working copy)
> @@ -16,7 +16,7 @@
>      eval "use DBD::SQLite";
>      plan $@
>          ? ( skip_all => 'needs DBD::SQLite for testing' )
> -        : ( tests => 64 );
> +        : ( tests => 66 );
>  }
>  
>  # figure out if we've got a version of sqlite that is older than 3.2.6, in
> @@ -469,3 +469,24 @@
>    );
>  
>  is($queries, 0, 'chained search_related after has_many->has_many prefetch ran no queries');
> +
> +
> +# Test again this time with multiple fanning prefetch paths ( M -> 1 -> M & M )
> +my $note_rs = $schema->resultset('LinerNotes')->search ({ notes => 'Buy Whiskey!' });
> +my $note_rs_pr = $note_rs->search({}, {
> +    prefetch => {
> +        cd => [qw/tracks tags/]     # <------ this fails
> +        #cd => [qw/tracks/]         # <------ this  works
> +    },
> +});
> +
> +$queries = 0;
> +$schema->storage->debugcb(sub { $queries++ });
> +$schema->storage->debug(1);
> +
> +my $count = $note_rs_pr->first->cd->tracks->count;
> +is($queries, 1, 'nested prefetch across many->single->(has_many,has_many) ran exactly 1 query');
> +
> +my $np_count = $note_rs->first->cd->tracks->count;
> +
> +is($count, $np_count, 'collapse of results over many->single->(has_many,has_many) prefetch');

> _______________________________________________
> 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/dbix-class@lists.rawmode.org

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list