From: Luke Saunders Date: Thu, 26 Jul 2007 21:31:08 +0000 (+0000) Subject: applied patch from davinch: fix bug with create_multi not inserting non-storage objects X-Git-Tag: v0.08010~111 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2bc3c81ece67606c69cfb18eaeebb05db706d776;p=dbsrgits%2FDBIx-Class.git applied patch from davinch: fix bug with create_multi not inserting non-storage objects --- diff --git a/Changes b/Changes index 10cb039..b86c2b5 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for DBIx::Class - + - fix bug with create_multi not inserting non-storage objects + (test and fix from davinchi) - DBIx::Class::AccessorGroup made empty subclass of Class::Accessor::Grouped - fixed an ugly bug regarding $dbh->{AutoCommit} and transactions diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index bb727d8..7195bba 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -76,8 +76,10 @@ sub new { my $rel_obj = delete $attrs->{$key}; if(!Scalar::Util::blessed($rel_obj)) { $rel_obj = $new->find_or_new_related($key, $rel_obj); - $new->{_rel_in_storage} = 0 unless ($rel_obj->in_storage); } + + $new->{_rel_in_storage} = 0 unless ($rel_obj->in_storage); + $new->set_from_related($key, $rel_obj); $related->{$key} = $rel_obj; next; @@ -90,6 +92,8 @@ sub new { $rel_obj = $new->new_related($key, $rel_obj); $new->{_rel_in_storage} = 0; } + + $new->{_rel_in_storage} = 0 unless ($rel_obj->in_storage); } $related->{$key} = $others; next; diff --git a/t/96multi_create.t b/t/96multi_create.t index 76fa85c..810b6eb 100644 --- a/t/96multi_create.t +++ b/t/96multi_create.t @@ -127,3 +127,37 @@ 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'); +}