From: Robert Buels Date: Tue, 10 May 2011 06:44:15 +0000 (-0700) Subject: make has-many rels accept a single hashref in populate, if there is just one thing... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0091c72a2f008e9342cbcfa47c75305a77351dcc;p=dbsrgits%2FDBIx-Class.git make has-many rels accept a single hashref in populate, if there is just one thing to insert. makes it a whole lot easier to insert from parsed config-like files --- diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 60c854b..495cf42 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -202,8 +202,9 @@ sub new { $related->{$key} = $rel_obj; next; } - elsif ($acc_type eq 'multi' && ref $attrs->{$key} eq 'ARRAY' ) { + elsif ($acc_type eq 'multi') { my $others = delete $attrs->{$key}; + $others = [ $others ] unless ref $others eq 'ARRAY'; my $total = @$others; my @objects; foreach my $idx (0 .. $#$others) { diff --git a/t/100populate.t b/t/100populate.t index 3109999..5aa706c 100644 --- a/t/100populate.t +++ b/t/100populate.t @@ -322,4 +322,14 @@ lives_ok ( sub { ]) }, 'empty has_many relationship accepted by populate'); +lives_ok ( sub { + $schema->populate('Artist', [ + { name => 'Snuggy Bottoms', + cds => { title => 'Hit My Singlet', year => 1973, + tracks => { title => 'Grunt', position => 0 }, + }, + }, + ]) +}, 'single hashref accepted by populate on has_many'); + done_testing;