From: Brian Phillips Date: Wed, 12 Jan 2011 18:46:32 +0000 (-0600) Subject: Fix populate with an emply ([]) has_many X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d6170b26eb0505a440a70c66ecd74c6df18ea2c1;p=dbsrgits%2FDBIx-Class-Historic.git Fix populate with an emply ([]) has_many these are ignored if they're empty which makes them much more compatible with HashRefInflator data sets --- diff --git a/Changes b/Changes index 043f9d4..be15c28 100644 --- a/Changes +++ b/Changes @@ -6,6 +6,8 @@ Revision history for DBIx::Class - Unaliased "dark" selectors no longer throw off prefetch - Fix proper composition of bind values across all possible SQL areas ( group_by => \[ ... ] now works properly ) + - Allow populate to skip empty has_many relationships which makes + it easier to pass HashRefInflator data directly to ->populate * Misc - Fix test warning on win32 - at this point the test suite is diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index 317d91c..979b653 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -256,6 +256,8 @@ blblack: Brandon L. Black bluefeet: Aran Deltac +bphillips: Brian Phillips + boghead: Bryan Beeley bricas: Brian Cassidy diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index a8e468c..b1f3360 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1971,7 +1971,7 @@ sub populate { foreach my $item (@$data) { foreach my $rel (@rels) { - next unless $item->{$rel} && ref $item->{$rel} eq "ARRAY"; + next unless ref $item->{$rel} eq "ARRAY" && @{ $item->{$rel} }; my $parent = $self->find({map { $_ => $item->{$_} } @pks}) || $self->throw_exception('Cannot find the relating object.'); diff --git a/t/100populate.t b/t/100populate.t index 8bb0fdc..c2c9491 100644 --- a/t/100populate.t +++ b/t/100populate.t @@ -315,4 +315,10 @@ lives_ok { }]) } 'multicol-PK has_many populate works'; +lives_ok ( sub { + $schema->populate('CD', [ + {cdid => 10001, artist => $artist->id, title => 'Pretty Much Empty', year => 2011, tracks => []}, + ]) +}, 'empty has_many relationship accepted by populate'); + done_testing;