<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"><<a href="mailto:rabbit+dbic@rabbit.us" target="_blank">rabbit+dbic@rabbit.us</a>></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'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 -> <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'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 "tracklist" 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 => 1 triggers, it can be found in this "double-recursion" 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 "last_track" in the CD test case and it does the job:<br><br> __PACKAGE__->has_many(<br> 'tracklist',<br> 'MyApp::Schema::Result::Track',<br> sub {<br> my $args = shift;<br><br> return (<br> {<br> "$args->{foreign_alias}.trackid" => { '-in' =><br> $args->{self_resultsource}->schema->resultset('Track')->search(<br> { 'cd.artist' => { -ident => "$args->{self_alias}.artistid" } },<br> {<br> join => 'cd',<br> alias => 'correlated_tracks',<br> columns => ['trackid']<br> },<br> )->as_query<br> }<br> }<br> );<br> },<br> );<br><br></div><div>Now I can use the "prefetch" 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'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>