2015-02-14 12:57 GMT+01:00 Peter Rabbitson <rabbit+d...@rabbit.us>: > > 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. >
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 -> https://metacpan.org/pod/DBIx::Class::Manual::Cookbook#Support 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? > In essence your best bet is to define a real relationship to "tracklist" > with the correct subquery and everything, like in this example: > https://github.com/dbsrgits/dbix-class/blob/current/for_ > cpan_index/t/lib/DBICTest/Schema/CD.pm#L120-L154 > > If you are interested in the inner logic that collapse => 1 triggers, it > can be found in this "double-recursion" function: > https://github.com/dbsrgits/dbix-class/blob/current/for_ > cpan_index/lib/DBIx/Class/ResultSource/RowParser.pm#L149-L398 > 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: __PACKAGE__->has_many( 'tracklist', 'MyApp::Schema::Result::Track', sub { my $args = shift; return ( { "$args->{foreign_alias}.trackid" => { '-in' => $args->{self_resultsource}->schema->resultset('Track')->search( { 'cd.artist' => { -ident => "$args->{self_alias}.artistid" } }, { join => 'cd', alias => 'correlated_tracks', columns => ['trackid'] }, )->as_query } } ); }, ); Now I can use the "prefetch" keyword in the search call. > If this reply isn't sufficient to answer your question - please ask > further. Your answer is very helpful and constructive! Thank you very much : )
_______________________________________________ List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk