9 my $schema = DBICTest->init_schema();
11 my $ars = $schema->resultset('Artist');
12 my $cdrs = $schema->resultset('CD');
13 my $cd2pr_rs = $schema->resultset('CD_to_Producer');
15 # create some custom entries
24 [qw/cdid artist title year/],
25 [qw/70 71 delete0 2005/],
26 [qw/71 72 delete1 2005/],
27 [qw/72 72 delete2 2005/],
28 [qw/73 72 delete3 2006/],
29 [qw/74 72 delete4 2007/],
30 [qw/75 73 delete5 2008/],
33 my $prod = $schema->resultset('Producer')->create ({ name => 'deleter' });
34 my $prod_cd = $cdrs->find (70);
35 my $cd2pr = $cd2pr_rs->create ({
40 my $total_cds = $cdrs->count;
42 # test that delete_related w/o conditions deletes all related records only
43 $ars->search ({name => 'a3' })->search_related ('cds')->delete;
44 is ($cdrs->count, $total_cds -= 1, 'related delete ok');
46 my $a2_cds = $ars->search ({ name => 'a2' })->search_related ('cds');
48 # test that related deletion w/conditions deletes just the matched related records only
49 $a2_cds->search ({ year => 2005 })->delete;
50 is ($cdrs->count, $total_cds -= 2, 'related + condition delete ok');
52 # test that related deletion with limit condition works
53 $a2_cds->search ({}, { rows => 1})->delete;
54 is ($cdrs->count, $total_cds -= 1, 'related + limit delete ok');
57 local $TODO = 'delete_related is based on search_related which is based on search which does not understand object arguments';
58 my $cd2pr_count = $cd2pr_rs->count;
59 $prod_cd->delete_related('cd_to_producer', { producer => $prod } );
60 is ($cd2pr_rs->count, $cd2pr_count -= 1, 'm2m link deleted succesfully');