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