[Dbix-class] prefetch syntax

Mark Hedges hedges at ucsd.edu
Fri Apr 7 19:17:57 CEST 2006



On Fri, 7 Apr 2006, Matt S Trout wrote:
> > 
> >        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".
> 
> Hmm. If it's already seen the alias, then it should add _2 the second time 
> around, which certainly works for e.g.
> 
> my $rs = $schema->resultset('TreeLike')->search(
>               $cond,
>               { prefetch => { parent => { parent => 'parent' } } } );
> 
> If it doesn't work the way you're trying it, evidently I didn't get the code 
> for this *quite* right.

Adding _2 works at the first level, which is why I figured it 
should work at the second level, but it doesn't.

> Any chance you could try and put together a test case against DBICTest?

Well, there's a chance I could try.  I'll let you know.

Mark



More information about the Dbix-class mailing list