6 eval "use DBIx::Class::CDBICompat;";
8 plan (skip_all => 'Class::Trigger and DBIx::ContextualFetch required');
11 eval "use DBD::SQLite";
12 plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 12);
16 use lib 't/cdbi/testlib';
22 Director->has_many(nasties => 'Film');
24 my $dir = Director->insert({
25 name => "Lewis Teague",
27 my $kk = $dir->add_to_nasties({
30 is $kk->director, $dir, "Director set OK";
31 is $dir->nasties, 1, "We have one nasty";
34 ok !Film->retrieve("Alligator"), "has_many cascade deletes by default";
38 # Two ways of saying not to cascade
39 for my $args ({ no_cascade_delete => 1 }, { cascade => "None" }) {
40 Director->has_many(nasties => 'Film', $args);
42 my $dir = Director->insert({
43 name => "Lewis Teague",
45 my $kk = $dir->add_to_nasties({
48 is $kk->director, $dir, "Director set OK";
49 is $dir->nasties, 1, "We have one nasty";
52 local $Data::Dumper::Terse = 1;
53 ok +Film->retrieve("Alligator"), 'has_many with ' . Dumper ($args);;
59 # local $TODO = 'cascade => "Fail" unimplemented';
61 # Director->has_many(nasties => Film => { cascade => 'Fail' });
63 # my $dir = Director->insert({ name => "Nasty Noddy" });
64 # my $kk = $dir->add_to_nasties({ Title => 'Killer Killers' });
65 # is $kk->director, $dir, "Director set OK";
66 # is $dir->nasties, 1, "We have one nasty";
68 # ok !eval { $dir->delete };
69 # like $@, qr/1/, "Can't delete while films exist";
71 # my $rr = $dir->add_to_nasties({ Title => 'Revenge of the Revengers' });
72 # ok !eval { $dir->delete };
73 # like $@, qr/2/, "Still can't delete";
75 # $dir->nasties->delete_all;
76 # ok eval { $dir->delete };
77 # is $@, '', "Can delete once films are gone";