Add permanent plumbing for _TempExtlib (d0435d75)
[dbsrgits/DBIx-Class.git] / t / multi_create / diamond.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
195ce039 3use strict;
4use warnings;
5
6use Test::More;
7use Test::Exception;
c0329273 8
195ce039 9use DBICTest;
10
11sub mc_diag { diag (@_) if $ENV{DBIC_MULTICREATE_DEBUG} };
12
13my $schema = DBICTest->init_schema();
14
15mc_diag (<<'DG');
16* Try a diamond multicreate
17
18Artist -> has_many -> Artwork_to_Artist -> belongs_to
19 /
20 belongs_to <- CD <- belongs_to <- Artwork <-/
21 \
22 \-> Artist2
23
24DG
25
26lives_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
54done_testing;