9 my $schema = DBICTest->init_schema(no_populate => 1);
11 $schema->resultset('Artist')->create({ name => 'JMJ', cds => [{
12 title => 'Magnetic Fields',
14 genre => { name => 'electro' },
23 $schema->resultset('CD')->create({
26 artist => { name => 'JMJ' },
27 genre => { name => 'electro' },
38 artist => { name => 'JMJ' },
40 { title => 'o2', position => 2}, # the position should not be here, bug in MC
46 my $rs = $schema->resultset ('CD')->search ({}, {
47 join => [ 'tracks', { single_track => { cd => { artist => { cds => 'tracks' } } } } ],
50 { 'year' => 'me.year' }, # non-unique
51 { 'genreid' => 'me.genreid' }, # nullable
52 { 'tracks.title' => 'tracks.title' }, # non-unique (no me.id)
53 { 'single_track.cd.artist.cds.cdid' => 'cds.cdid' }, # to give uniquiness to ...tracks.title below
54 { 'single_track.cd.artist.artistid' => 'artist.artistid' }, # uniqufies entire parental chain
55 { 'single_track.cd.artist.cds.year' => 'cds.year' }, # non-unique
56 { 'single_track.cd.artist.cds.genreid' => 'cds.genreid' }, # nullable
57 { 'single_track.cd.artist.cds.tracks.title' => 'tracks_2.title' }, # unique when combined with ...cds.cdid above
58 { 'latest_cd' => \ "(SELECT MAX(year) FROM cd)" }, # random function
59 { 'title' => 'me.title' }, # uniquiness for me
60 { 'artist' => 'me.artist' }, # uniquiness for me
62 order_by => [{ -desc => 'cds.year' }, { -desc => 'me.title'} ],
65 my $hri_rs = $rs->search({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' });
149 single_track => undef,
165 single_track => undef,
166 title => "Magnetic Fields",
184 'W00T, manual prefetch with collapse works'
190 local $TODO = 'Something is wrong with filter type rels, they throw on incomplete objects >.<';
194 { $row->single_track->get_columns },
196 'empty intermediate object ok',
201 is ($rs->cursor->next, undef, 'cursor exhausted');
204 local $TODO = 'this does not work at all, need to promote rsattrs to an object on its own';
205 # make sure has_many column redirection does not do weird stuff when collapse is requested
207 { prefetch => 'cds'},
210 for my $col_and_join_args (
211 { '+columns' => { 'cd_title' => 'cds_2.title' }, join => [ 'cds', 'cds' ] },
212 { '+columns' => { 'cd_title' => 'cds.title' }, join => 'cds', }
215 my $weird_rs = $schema->resultset('Artist')->search({}, {
216 %$col_and_join_args, %$pref_args,
219 for (qw/next all first/) {
220 throws_ok { $weird_rs->$_ } qr/not yet determined exception text/;