Skip to content

Commit

Permalink
Fix populate with an emply ([]) has_many
Browse files Browse the repository at this point in the history
these are ignored if they're empty which makes them much more
compatible with HashRefInflator data sets
  • Loading branch information
Brian Phillips authored and ribasushi committed Jan 12, 2011
1 parent 1239d14 commit d6170b2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/DBIx/Class.pm
Expand Up @@ -256,6 +256,8 @@ blblack: Brandon L. Black <blblack@gmail.com>
bluefeet: Aran Deltac <bluefeet@cpan.org>
bphillips: Brian Phillips <bphillips@cpan.org>
boghead: Bryan Beeley <cpan@beeley.org>
bricas: Brian Cassidy <bricas@cpan.org>
Expand Down
2 changes: 1 addition & 1 deletion lib/DBIx/Class/ResultSet.pm
Expand Up @@ -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.');
Expand Down
6 changes: 6 additions & 0 deletions t/100populate.t
Expand Up @@ -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;

0 comments on commit d6170b2

Please sign in to comment.