I reckon you'd have to <br><br><div><span class="gmail_quote">On 4/7/06, <b class="gmail_sendername">Mark Hedges</b> <<a href="mailto:hedges@ucsd.edu">hedges@ucsd.edu</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>On Fri, 7 Apr 2006, Jason Galea wrote:<br><br>> not much more than a shot in the dark, but something similar to this worked<br>> for me the other day..<br>><br>> my $rs = $schema->resultset('Foo')->search(
<br>> { 'me.foo_id' => $foo_id },<br>> { prefetch => [<br>> 'baz',<br>> { bar => 'biz' }<br>> ],
<br>> },<br>> );<br><br>Oh I get it. Thanks, that works nicely.<br><br>I do have another prefetch problem where I try to two-tier join the<br>same class through two different relationship tables. I try this now:
<br><br> my $rs = $schema->resultset('Foo')->search(<br> { 'me.foo_id' => $foo_id },<br> { prefetch => [<br> { bar => 'biz' },<br> { bee => 'biz' },<br> ],
<br> },<br> );<br><br>or equivalently:<br><br> my $rs = $schema->resultset('Foo')->search(<br> { 'me.foo_id' => $foo_id },<br> { prefetch => {<br> bar => 'biz',<br>
bee => 'biz',<br> },<br> },<br> );<br><br>The sql that results does something like<br><br> LEFT JOIN bar bar ON foo.foo_id = bar.foo_id<br> LEFT JOIN biz biz ON bar.bar_id = biz.bar_id
<br> LEFT JOIN bee bee ON foo.foo_id = bee.foo_id<br> LEFT JOIN biz biz ON bar.bar_id = biz.bar_id<br><br>and DBI throws "Not unique table/alias 'biz' at script line x".<br><br>Unfortunately I'm dense and I don't get the join syntax...
<br>would that solve this? There are so many confusing mixes<br>of scalars, arrayrefs and hashrefs I'm not sure what I'm doing.<br><br>Thanks if someone has worked this out....<br><br>Mark<br><br>_______________________________________________
<br>List: <a href="http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class">http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class</a><br>Wiki: <a href="http://dbix-class.shadowcatsystems.co.uk/">http://dbix-class.shadowcatsystems.co.uk/
</a><br>IRC: irc.perl.org#dbix-class<br>SVN: <a href="http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/">http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/</a></blockquote><div><br>As far as I can see, the only way out of it is to rename one of the two relationships to 'biz2' or whatever. That's essentially what you'd have to do if you were writing the query in SQL right?
<br><br>Alternatively, I think it may be possible to do what you want using the -from attribute, but you might go mad trying. Read: <a href="http://search.cpan.org/~mstrout/DBIx-Class-0.06000/lib/DBIx/Class/ResultSet.pm#from">
http://search.cpan.org/~mstrout/DBIx-Class-0.06000/lib/DBIx/Class/ResultSet.pm#from</a><br><br>Perhaps it would be nice if it were possible to assign aliases to relationships for situations such as this:<br>Your::Schema::Bar->belongs_to('biz', 'Your::Schema::Biz', undef,
<br> { aliases => ['biz2', 'other_alias'] });<br></div></div>Overkill probably.<br>