X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F96multi_create.t;h=d89856347f327e1cdadeafb493ec773647e730fc;hb=c1cac6332247a092ddc886c52607b24104c3fb46;hp=76fa85c48290cac5556b94399f6562f537d52325;hpb=e5dddc052141584da501243ae42d53f522a5cc69;p=dbsrgits%2FDBIx-Class.git diff --git a/t/96multi_create.t b/t/96multi_create.t index 76fa85c..d898563 100644 --- a/t/96multi_create.t +++ b/t/96multi_create.t @@ -51,6 +51,23 @@ my $newartist2 = $schema->resultset('Artist')->find_or_create({ name => 'Fred 3' is($newartist2->name, 'Fred 3', 'Created new artist with cds via find_or_create'); +my $artist2 = $schema->resultset('Artist')->create({ artistid => 1000, + name => 'Fred 3', + cds => [ + { artist => 1000, + title => 'Music to code by', + year => 2007, + }, + ], + cds_unordered => [ + { artist => 1000, + title => 'Music to code by', + year => 2007, + }, + ] + }); + +is($artist2->in_storage, 1, 'artist with duplicate rels inserted okay'); CREATE_RELATED1 :{ @@ -127,3 +144,53 @@ my $cdp = $schema->resultset('CD_to_Producer')->create({ }); ok($cdp, 'join table record created ok'); + +SPECIAL_CASE: { + my $kurt_cobain = { name => 'Kurt Cobain' }; + + my $in_utero = $schema->resultset('CD')->new({ + title => 'In Utero', + year => 1993 + }); + + $kurt_cobain->{cds} = [ $in_utero ]; + + + $schema->resultset('Artist')->populate([ $kurt_cobain ]); # %) + $a = $schema->resultset('Artist')->find({name => 'Kurt Cobain'}); + + is($a->name, 'Kurt Cobain', 'Artist insertion ok'); + is($a->cds && $a->cds->first && $a->cds->first->title, + 'In Utero', 'CD insertion ok'); +} + +SPECIAL_CASE2: { + my $pink_floyd = { name => 'Pink Floyd' }; + + my $the_wall = { title => 'The Wall', year => 1979 }; + + $pink_floyd->{cds} = [ $the_wall ]; + + + $schema->resultset('Artist')->populate([ $pink_floyd ]); # %) + $a = $schema->resultset('Artist')->find({name => 'Pink Floyd'}); + + is($a->name, 'Pink Floyd', 'Artist insertion ok'); + is($a->cds && $a->cds->first->title, 'The Wall', 'CD insertion ok'); +} + +## Create foreign key col obj including PK +## See test 20 in 66relationships.t +my $new_cd_hashref = { + cdid => 27, + title => 'Boogie Woogie', + year => '2007', + artist => { artistid => 17, name => 'king luke' } + }; + +my $cd = $schema->resultset("CD")->find(1); + +is($cd->artist->id, 1, 'rel okay'); + +my $new_cd = $schema->resultset("CD")->create($new_cd_hashref); +is($new_cd->artist->id, 17, 'new id retained okay');