9 sub mc_diag { diag (@_) if $ENV{DBIC_MULTICREATE_DEBUG} };
13 my $schema = DBICTest->init_schema();
16 * Test a multilevel might-have/has_one with a PK == FK in the mid-table
18 CD -> might have -> Artwork
29 has_one => 'mandatory_artwork',
30 might_have => 'artwork',
33 my $artist_rs = $schema->resultset('Artist');
35 for my $type (qw/has_one might_have/) {
37 my $rel = $rels->{$type};
39 my $cd_title = "Test $type cd";
40 my $artist_names = [ map { "Artist via $type $_" } (1, 2) ];
42 my $someartist = $artist_rs->next;
45 my $cd = $schema->resultset('CD')->create ({
46 artist => $someartist,
50 artwork_to_artist => [ map {
51 { artist => { name => $_ } }
58 isa_ok ($cd, 'DBICTest::CD', 'Main CD object created');
59 is ($cd->title, $cd_title, 'Correct CD title');
61 my $art_obj = $cd->$rel;
62 ok ($art_obj->has_column_loaded ('cd_id'), 'PK/FK present on artwork object');
63 is ($art_obj->artists->count, 2, 'Correct artwork creator count via the new object');
65 [ sort $art_obj->artists->get_column ('name')->all ],
67 'Artists named correctly when queried via object',
70 my $artwork = $schema->resultset('Artwork')->search (
71 { 'cd.title' => $cd_title },
74 is ($artwork->artists->count, 2, 'Correct artwork creator count via a new search');
76 [ sort $artwork->artists->get_column ('name')->all ],
78 'Artists named correctly queried via a new search',
80 }, "multilevel $type with a PK == FK in the $type/has_many table ok");