[Dbix-class] multi-path prefetches
Mark Hedges
hedges at ucsd.edu
Fri Mar 31 01:34:23 CEST 2006
Did I use prefetch wrong here?
Suppose:
foo 1:M bars
foo 1:M bizs
bar 1:1 baz
biz 1:1 baz
I.e. a foo has bazzes through two different relationship paths.
(i.e. a customer bought a baz and uses it too, or maybe they
bought it and gave it to someone else.)
my $rs = $schema->resultset('Foo')->search(
{ 'me.email' => $foo_email },
{ prefetch => {
bar => 'baz',
biz => 'baz',
}
},
);
my $foo = $rs->next();
DBIx::Class::ResultSet::next(): Error executing
'SELECT me.email,
bars.email,
bars.baz_id,
baz.baz_id,
baz.name,
bizs.email,
bizs.baz_id,
baz_2.baz_id,
baz_2.name,
FROM foo me
LEFT JOIN bar bars
ON ( bars.email = me.email )
JOIN baz baz
ON ( baz.baz_id = bars.baz_id )
LEFT JOIN biz bizs
ON ( bizs.email = me.email )
JOIN baz baz_2
ON ( baz_2.baz_id = bizs.baz_id )
LEFT JOIN bar bars -- seems like here
ON ( bars.email = me.email )
JOIN baz baz
ON ( baz.baz_id = bars.baz_id )
LEFT JOIN biz bizs
ON ( bizs.email = me.email )
JOIN baz baz_2
ON ( baz_2.baz_id = bizs.baz_id ) -- to here was duplicated for no reason
WHERE ( me.email = ? )
ORDER BY bars.email, bizs.email':
Not unique table/alias: 'bars' at <my script> line 18
More information about the Dbix-class
mailing list