From d6170b26eb0505a440a70c66ecd74c6df18ea2c1 Mon Sep 17 00:00:00 2001 From: Brian Phillips Date: Wed, 12 Jan 2011 12:46:32 -0600 Subject: [PATCH] Fix populate with an emply ([]) has_many these are ignored if they're empty which makes them much more compatible with HashRefInflator data sets --- Changes | 2 ++ lib/DBIx/Class.pm | 2 ++ lib/DBIx/Class/ResultSet.pm | 2 +- t/100populate.t | 6 ++++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 043f9d4d4..be15c28a7 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 317d91c63..979b65378 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 a8e468c04..b1f3360e6 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 8bb0fdc66..c2c94918f 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;