[Dbix-class] prefetch syntax

Mark Hedges hedges at ucsd.edu
Fri Apr 7 03:11:43 CEST 2006


On Fri, 7 Apr 2006, Jason Galea wrote:

> not much more than a shot in the dark, but something similar to this worked
> for me the other day..
> 
>      my $rs = $schema->resultset('Foo')->search(
>          {   'me.foo_id' => $foo_id  },
>          {   prefetch    => [
>                               'baz',
>                               { bar => 'biz' }
>                             ],
>          },
>      );

Oh I get it.  Thanks, that works nicely.

I do have another prefetch problem where I try to two-tier join the 
same class through two different relationship tables.  I try this now:

   my $rs = $schema->resultset('Foo')->search(
       {   'me.foo_id' => $foo_id  },
       {   prefetch    => [
               { bar => 'biz' },
               { bee => 'biz' },
           ],
       },
   );

or equivalently:

   my $rs = $schema->resultset('Foo')->search(
       {   'me.foo_id' => $foo_id  },
       {   prefetch    => {
               bar => 'biz',
               bee => 'biz',
           },
       },
   );

The sql that results does something like 

    LEFT JOIN bar bar ON foo.foo_id = bar.foo_id
    LEFT JOIN biz biz ON bar.bar_id = biz.bar_id
    LEFT JOIN bee bee ON foo.foo_id = bee.foo_id
    LEFT JOIN biz biz ON bar.bar_id = biz.bar_id

and DBI throws "Not unique table/alias 'biz' at script line x".

Unfortunately I'm dense and I don't get the join syntax...
would that solve this?  There are so many confusing mixes
of scalars, arrayrefs and hashrefs I'm not sure what I'm doing.

Thanks if someone has worked this out....

Mark



More information about the Dbix-class mailing list