Commit | Line | Data |
c0329273 |
1 | BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } |
2 | |
195ce039 |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
7 | use Test::Exception; |
c0329273 |
8 | |
195ce039 |
9 | use DBICTest; |
10 | |
11 | sub mc_diag { diag (@_) if $ENV{DBIC_MULTICREATE_DEBUG} }; |
12 | |
13 | my $schema = DBICTest->init_schema(); |
14 | |
15 | mc_diag (<<'DG'); |
16 | * Try a diamond multicreate |
17 | |
18 | Artist -> has_many -> Artwork_to_Artist -> belongs_to |
19 | / |
20 | belongs_to <- CD <- belongs_to <- Artwork <-/ |
21 | \ |
22 | \-> Artist2 |
23 | |
24 | DG |
25 | |
26 | lives_ok (sub { |
27 | $schema->resultset ('Artist')->create ({ |
28 | name => 'The wooled wolf', |
29 | artwork_to_artist => [{ |
30 | artwork => { |
31 | cd => { |
32 | title => 'Wool explosive', |
33 | year => 1999, |
34 | artist => { name => 'The black exploding sheep' }, |
35 | } |
36 | } |
37 | }], |
38 | }); |
39 | |
40 | my $art2 = $schema->resultset ('Artist')->find ({ name => 'The black exploding sheep' }); |
41 | ok ($art2, 'Second artist exists'); |
42 | |
43 | my $cd = $art2->cds->single; |
44 | is ($cd->title, 'Wool explosive', 'correctly created CD'); |
45 | |
46 | is_deeply ( |
47 | [ $cd->artwork->artists->get_column ('name')->all ], |
48 | [ 'The wooled wolf' ], |
49 | 'Artist correctly attached to artwork', |
50 | ); |
51 | |
52 | }, 'Diamond chain creation ok'); |
53 | |
54 | done_testing; |