9 # This set of tests attempts to do a delete on a chained resultset, which
10 # would lead to SQL DELETE with a JOIN, which is not supported by the
11 # SQL generator right now.
12 # So it currently checks that these operations fail with a warning.
13 # When the SQL generator is fixed this test will need fixing up appropriately.
15 my $schema = DBICTest->init_schema();
16 my $total_tracks = $schema->resultset('Track')->count;
17 cmp_ok($total_tracks, '>', 0, 'need track records');
19 # test that delete_related w/o conditions deletes all related records only
22 local $SIG{__WARN__} = sub { $w = shift };
24 my $artist = $schema->resultset("Artist")->find(3);
25 my $artist_tracks = $artist->cds->search_related('tracks')->count;
26 cmp_ok($artist_tracks, '<', $total_tracks, 'need more tracks than just related tracks');
28 my $rs = $artist->cds->search_related('tracks');
29 $total_tracks -= $rs->count;
31 is($schema->resultset('Track')->count, $total_tracks, '3 tracks should be deleted');
34 # test that delete_related w/conditions deletes just the matched related records only
37 local $SIG{__WARN__} = sub { $w = shift };
39 my $artist2 = $schema->resultset("Artist")->find(2);
40 my $artist2_tracks = $artist2->search_related('cds')->search_related('tracks')->count;
41 cmp_ok($artist2_tracks, '<', $total_tracks, 'need more tracks than related tracks');
43 my $rs = $artist2->search_related('cds')->search_related('tracks');
44 $total_tracks -= $rs->count;
46 is($schema->resultset('Track')->count, $total_tracks, 'No tracks should be deleted');