8 my $schema = DBICTest->init_schema();
10 my $ars = $schema->resultset('Artist');
11 my $cdrs = $schema->resultset('CD');
12 my $cd2pr_rs = $schema->resultset('CD_to_Producer');
14 # create some custom entries
23 [qw/cdid artist title year/],
24 [qw/70 71 delete0 2005/],
25 [qw/71 72 delete1 2005/],
26 [qw/72 72 delete2 2005/],
27 [qw/73 72 delete3 2006/],
28 [qw/74 72 delete4 2007/],
29 [qw/75 73 delete5 2008/],
32 my $prod = $schema->resultset('Producer')->create ({ name => 'deleter' });
33 my $prod_cd = $cdrs->find (70);
34 my $cd2pr = $cd2pr_rs->create ({
39 my $total_cds = $cdrs->count;
41 # test that delete_related w/o conditions deletes all related records only
42 $ars->search ({name => 'a3' })->search_related ('cds')->delete;
43 is ($cdrs->count, $total_cds -= 1, 'related delete ok');
45 my $a2_cds = $ars->search ({ name => 'a2' })->search_related ('cds');
47 # test that related deletion w/conditions deletes just the matched related records only
48 $a2_cds->search ({ year => 2005 })->delete;
49 is ($cdrs->count, $total_cds -= 2, 'related + condition delete ok');
51 # test that related deletion with limit condition works
52 $a2_cds->search ({}, { rows => 1})->delete;
53 is ($cdrs->count, $total_cds -= 1, 'related + limit delete ok');
56 local $TODO = 'delete_related is based on search_related which is based on search which does not understand object arguments';
57 local $SIG{__WARN__} = sub {}; # trap the non-numeric warning, remove when the TODO is removed
59 my $cd2pr_count = $cd2pr_rs->count;
60 $prod_cd->delete_related('cd_to_producer', { producer => $prod } );
61 is ($cd2pr_rs->count, $cd2pr_count -= 1, 'm2m link deleted succesfully');
63 # see 187ec69a for why this is neccessary
64 $prod->result_source(undef);