I reckon you'd have to <br><br><div><span class="gmail_quote">On 4/7/06, <b class="gmail_sendername">Mark Hedges</b> &lt;<a href="mailto:hedges@ucsd.edu">hedges@ucsd.edu</a>&gt; 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>&gt; not much more than a shot in the dark, but something similar to this worked<br>&gt; for me the other day..<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my $rs = $schema-&gt;resultset('Foo')-&gt;search(
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp; 'me.foo_id' =&gt; $foo_id&nbsp;&nbsp;},<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp; prefetch&nbsp;&nbsp;&nbsp;&nbsp;=&gt; [<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'baz',<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { bar =&gt; 'biz' }<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ],
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br><br>Oh I get it.&nbsp;&nbsp;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.&nbsp;&nbsp;I try this now:
<br><br>&nbsp;&nbsp; my $rs = $schema-&gt;resultset('Foo')-&gt;search(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp; 'me.foo_id' =&gt; $foo_id&nbsp;&nbsp;},<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp; prefetch&nbsp;&nbsp;&nbsp;&nbsp;=&gt; [<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { bar =&gt; 'biz' },<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { bee =&gt; 'biz' },<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ],
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br>&nbsp;&nbsp; );<br><br>or equivalently:<br><br>&nbsp;&nbsp; my $rs = $schema-&gt;resultset('Foo')-&gt;search(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp; 'me.foo_id' =&gt; $foo_id&nbsp;&nbsp;},<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp; prefetch&nbsp;&nbsp;&nbsp;&nbsp;=&gt; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bar =&gt; 'biz',<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bee =&gt; 'biz',<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br>&nbsp;&nbsp; );<br><br>The sql that results does something like<br><br>&nbsp;&nbsp;&nbsp;&nbsp;LEFT JOIN bar bar ON foo.foo_id = bar.foo_id<br>&nbsp;&nbsp;&nbsp;&nbsp;LEFT JOIN biz biz ON bar.bar_id = biz.bar_id
<br>&nbsp;&nbsp;&nbsp;&nbsp;LEFT JOIN bee bee ON foo.foo_id = bee.foo_id<br>&nbsp;&nbsp;&nbsp;&nbsp;LEFT JOIN biz biz ON bar.bar_id = biz.bar_id<br><br>and DBI throws &quot;Not unique table/alias 'biz' at script line x&quot;.<br><br>Unfortunately I'm dense and I don't get the join syntax...
<br>would that solve this?&nbsp;&nbsp;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'&nbsp; 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-&gt;belongs_to('biz', 'Your::Schema::Biz', undef,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { aliases =&gt; ['biz2', 'other_alias'] });<br></div></div>Overkill probably.<br>