marked DBIx::Class::DB as deprecated and due to be removed by 1.0
[dbsrgits/DBIx-Class.git] / t / 53delete_related.t
1 use Test::More;
2 use strict;
3 use warnings;
4 use lib qw(t/lib);
5 use DBICTest;
6 use DBICTest::BasicRels;
7
8 plan tests => 7;
9
10 my $schema = DBICTest->schema;
11 my $total_cds = $schema->resultset('CD')->count;
12 cmp_ok($total_cds, '>', 0, 'need cd records');
13
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');
18
19 ok($artist->delete_related('cds'));
20 cmp_ok($schema->resultset('CD')->count, '==', ($total_cds - $artist_cds), 'too many cds were deleted');
21
22 $total_cds -= $artist_cds;
23
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');
28
29 ok($artist2->delete_related('cds', {title => {like => '%'}}));
30 cmp_ok($schema->resultset('CD')->count, '==', ($total_cds - $artist2_cds), 'too many cds were deleted');