<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2015-02-14 12:57 GMT+01:00 Peter Rabbitson <span dir="ltr">&lt;<a href="mailto:rabbit+dbic@rabbit.us" target="_blank">rabbit+dbic@rabbit.us</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>Note that the above usage is unsupported (specifying a from structure by hand may or may not work this way). [...] this *will* stop working in the distant future.<br></blockquote><br>Normally I don&#39;t use it. I just did to find a solution for this special case and because ... ^_^ ... the documentation (still) says sub queries are supported with the from keyword -&gt; <a href="https://metacpan.org/pod/DBIx::Class::Manual::Cookbook#Support" target="_blank">https://metacpan.org/pod/DBIx::Class::Manual::Cookbook#Support</a><br><br></div><div class="gmail_quote">But thanks for that information, I will avoid it. Is it appropriate to contribute a fix for the Cookbook&#39;s POD or should I consult somebody before?<br></div><div class="gmail_quote"> <br></div><div class="gmail_quote"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>

In essence your best bet is to define a real relationship to &quot;tracklist&quot; with the correct subquery and everything, like in this example: <a href="https://github.com/dbsrgits/dbix-class/blob/current/for_cpan_index/t/lib/DBICTest/Schema/CD.pm#L120-L154" target="_blank">https://github.com/dbsrgits/<u></u>dbix-class/blob/current/for_<u></u>cpan_index/t/lib/DBICTest/<u></u>Schema/CD.pm#L120-L154</a><br>
<br>
If you are interested in the inner logic that collapse =&gt; 1 triggers, it can be found in this &quot;double-recursion&quot; function: <a href="https://github.com/dbsrgits/dbix-class/blob/current/for_cpan_index/lib/DBIx/Class/ResultSource/RowParser.pm#L149-L398" target="_blank">https://github.com/dbsrgits/<u></u>dbix-class/blob/current/for_<u></u>cpan_index/lib/DBIx/Class/<u></u>ResultSource/RowParser.pm#<u></u>L149-L398</a><br></blockquote><div><br></div><div>Thanks for pointing out those lines. I wrote a relationship very similar to &quot;last_track&quot; in the CD test case and it does the job:<br><br>    __PACKAGE__-&gt;has_many(<br>        &#39;tracklist&#39;,<br>        &#39;MyApp::Schema::Result::Track&#39;,<br>        sub {<br>            my $args = shift;<br><br>            return (<br>                {<br>                    &quot;$args-&gt;{foreign_alias}.trackid&quot; =&gt; { &#39;-in&#39; =&gt;<br>                        $args-&gt;{self_resultsource}-&gt;schema-&gt;resultset(&#39;Track&#39;)-&gt;search(<br>                            { &#39;cd.artist&#39; =&gt; { -ident =&gt; &quot;$args-&gt;{self_alias}.artistid&quot; } },<br>                            {<br>                                join =&gt; &#39;cd&#39;,<br>                                alias =&gt; &#39;correlated_tracks&#39;,<br>                                columns =&gt; [&#39;trackid&#39;]<br>                            },<br>                        )-&gt;as_query<br>                    }<br>                }<br>            );<br>        },<br>    );<br><br></div><div>Now I can use the &quot;prefetch&quot; keyword in the search call.<br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

If this reply isn&#39;t sufficient to answer your question - please ask further.</blockquote><div>Your answer is very helpful and constructive! Thank you very much : )<br></div><br></div><br></div></div>