Move relationships out of Relationships.pm and in to the respective classes. Removed...
[dbsrgits/DBIx-Class.git] / t / 53delete_related.t
CommitLineData
c6ce6ec6 1use Test::More;
2use strict;
3use warnings;
4use lib qw(t/lib);
5use DBICTest;
6use DBICTest::BasicRels;
7
8plan tests => 7;
9
10my $schema = DBICTest->schema;
11my $total_cds = $schema->resultset('CD')->count;
12cmp_ok($total_cds, '>', 0, 'need cd records');
13
14# test that delete_related w/o conditions deletes all related records only
15my $artist = $schema->resultset("Artist")->find(3);
16my $artist_cds = $artist->cds->count;
17cmp_ok($artist_cds, '<', $total_cds, 'need more cds than just related cds');
18
19ok($artist->delete_related('cds'));
20cmp_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
25my $artist2 = $schema->resultset("Artist")->find(2);
26my $artist2_cds = $artist2->search_related('cds')->count;
27cmp_ok($artist2_cds, '<', $total_cds, 'need more cds than related cds');
28
29ok($artist2->delete_related('cds', {title => {like => '%'}}));
30cmp_ok($schema->resultset('CD')->count, '==', ($total_cds - $artist2_cds), 'too many cds were deleted');