new config option to DBICTest to let you set an alternative storage type, start on...
[dbsrgits/DBIx-Class.git] / t / 53delete_related.t
CommitLineData
c6ce6ec6 1use Test::More;
2use strict;
3use warnings;
4use lib qw(t/lib);
5use DBICTest;
c6ce6ec6 6
7plan tests => 7;
8
ae515736 9my $schema = DBICTest->init_schema();
c6ce6ec6 10my $total_cds = $schema->resultset('CD')->count;
11cmp_ok($total_cds, '>', 0, 'need cd records');
12
13# test that delete_related w/o conditions deletes all related records only
14my $artist = $schema->resultset("Artist")->find(3);
15my $artist_cds = $artist->cds->count;
16cmp_ok($artist_cds, '<', $total_cds, 'need more cds than just related cds');
17
18ok($artist->delete_related('cds'));
19cmp_ok($schema->resultset('CD')->count, '==', ($total_cds - $artist_cds), 'too many cds were deleted');
20
21$total_cds -= $artist_cds;
22
23# test that delete_related w/conditions deletes just the matched related records only
24my $artist2 = $schema->resultset("Artist")->find(2);
25my $artist2_cds = $artist2->search_related('cds')->count;
26cmp_ok($artist2_cds, '<', $total_cds, 'need more cds than related cds');
27
28ok($artist2->delete_related('cds', {title => {like => '%'}}));
29cmp_ok($schema->resultset('CD')->count, '==', ($total_cds - $artist2_cds), 'too many cds were deleted');
a5f761f7 30