9 my $schema = DBICTest->init_schema();
10 my $total_cds = $schema->resultset('CD')->count;
11 cmp_ok($total_cds, '>', 0, 'need cd records');
13 # test that delete_related w/o conditions deletes all related records only
14 my $artist = $schema->resultset("Artist")->find(3);
15 my $artist_cds = $artist->cds->count;
16 cmp_ok($artist_cds, '<', $total_cds, 'need more cds than just related cds');
18 ok($artist->delete_related('cds'));
19 cmp_ok($schema->resultset('CD')->count, '==', ($total_cds - $artist_cds), 'too many cds were deleted');
21 $total_cds -= $artist_cds;
23 # test that delete_related w/conditions deletes just the matched related records only
24 my $artist2 = $schema->resultset("Artist")->find(2);
25 my $artist2_cds = $artist2->search_related('cds')->count;
26 cmp_ok($artist2_cds, '<', $total_cds, 'need more cds than related cds');
28 ok($artist2->delete_related('cds', {title => {like => '%'}}));
29 cmp_ok($schema->resultset('CD')->count, '==', ($total_cds - $artist2_cds), 'too many cds were deleted');