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