From: Peter Rabbitson Date: Sat, 30 May 2009 17:46:09 +0000 (+0000) Subject: populate() fix and Changes X-Git-Tag: v0.08106~49 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4242d79d40be0fc4888c9da3d77a5a442c16d8d0;p=dbsrgits%2FDBIx-Class.git populate() fix and Changes --- diff --git a/Changes b/Changes index 1317943..9c7b91e 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ Revision history for DBIx::Class + - populate() now properly reports the dataset slice in case of + an exception + - fixed corner case when populate() erroneously falls back to + create() + 0.08103 2009-05-26 19:50:00 (UTC) - Multiple $resultset -> count/update/delete fixes. Now any of these operations will succeed, regardless of the complexity diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 282651f..b53e85c 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1665,13 +1665,19 @@ sub populate { ## do the belongs_to relationships foreach my $index (0..$#$data) { - if( grep { !defined $data->[$index]->{$_} } @pks ) { - my @ret = $self->populate($data); - return; + + # delegate to create() for any dataset without primary keys with specified relationships + if (grep { !defined $data->[$index]->{$_} } @pks ) { + for my $r (@rels) { + if (grep { ref $data->[$index]{$r} eq $_ } qw/HASH ARRAY/) { # a related set must be a HASH or AoH + my @ret = $self->populate($data); + return; + } + } } foreach my $rel (@rels) { - next unless $data->[$index]->{$rel} && ref $data->[$index]->{$rel} eq "HASH"; + next unless ref $data->[$index]->{$rel} eq "HASH"; my $result = $self->related_resultset($rel)->create($data->[$index]->{$rel}); my ($reverse) = keys %{$self->result_source->reverse_relationship_info($rel)}; my $related = $result->result_source->_resolve_condition( diff --git a/t/100populate.t b/t/100populate.t index 51d3fcf..ec765aa 100644 --- a/t/100populate.t +++ b/t/100populate.t @@ -39,7 +39,6 @@ throws_ok ( sub { $schema->populate('CD', [ map { { - cdid => $i++, # without a PK the bulk insert does not engage - how come? artist => $artist->id, title => $_, year => 2009,