my $collapse = $attrs->{collapse} || {};
+
if ( my $prefetch = delete $attrs->{prefetch} ) {
$prefetch = $self->_merge_attr( {}, $prefetch );
- my @pre_order;
- foreach my $p ( ref $prefetch eq 'ARRAY' ? @$prefetch : ($prefetch) ) {
-
- # bring joins back to level of current class
- my $join_map = $self->_joinpath_aliases ($attrs->{from}, $attrs->{seen_join});
- my @prefetch =
- $source->_resolve_prefetch( $p, $alias, $join_map, \@pre_order, $collapse );
- push( @{ $attrs->{select} }, map { $_->[0] } @prefetch );
- push( @{ $attrs->{as} }, map { $_->[1] } @prefetch );
- }
- push( @{ $attrs->{order_by} }, @pre_order );
+
+ my $prefetch_ordering = [];
+
+ my $join_map = $self->_joinpath_aliases ($attrs->{from}, $attrs->{seen_join});
+
+ my @prefetch =
+ $source->_resolve_prefetch( $prefetch, $alias, $join_map, $prefetch_ordering, $collapse );
+
+ push( @{ $attrs->{select} }, map { $_->[0] } @prefetch );
+ push( @{ $attrs->{as} }, map { $_->[1] } @prefetch );
+
+ push( @{ $attrs->{order_by} }, @$prefetch_ordering );
}
if (delete $attrs->{distinct}) {
my $schema = DBICTest->init_schema();
-my $orig_debug = $schema->storage->debug;
-
-use IO::File;
-
-BEGIN {
- eval "use DBD::SQLite";
- plan $@
- ? ( skip_all => 'needs DBD::SQLite for testing' )
- : ( tests => 3 );
-}
+plan tests => 3;
# bug in 0.07000 caused attr (join/prefetch) to be modifed by search
# so we check the search & attr arrays are not modified
--- /dev/null
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBIC::SqlMakerTest;
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+plan tests => 1;
+
+# While this is a rather GIGO case, make sure it behaves as pre-103,
+# as it may result in hard-to-track bugs
+my $cds = $schema->resultset('Artist')
+ ->search_related ('cds')
+ ->search ({}, {
+ prefetch => [ 'single_track', { single_track => 'cd' } ],
+ });
+
+is_same_sql(
+ ${$cds->as_query}->[0],
+ '(
+ SELECT
+ cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track,
+ single_track.trackid, single_track.cd, single_track.position, single_track.title, single_track.last_updated_on, single_track.last_updated_at,
+ single_track_2.trackid, single_track_2.cd, single_track_2.position, single_track_2.title, single_track_2.last_updated_on, single_track_2.last_updated_at,
+ cd.cdid, cd.artist, cd.title, cd.year, cd.genreid, cd.single_track
+ FROM artist me
+ LEFT JOIN cd cds ON cds.artist = me.artistid
+ LEFT JOIN track single_track ON single_track.trackid = cds.single_track
+ LEFT JOIN track single_track_2 ON single_track_2.trackid = cds.single_track
+ LEFT JOIN cd cd ON cd.cdid = single_track_2.cd
+ )',
+);