From: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Date: Mon, 21 May 2007 20:23:36 +0000 (+0000)
Subject: Copy the working mk_hash from HashRefInflator in -current into Cookbook
X-Git-Tag: v0.08010~156
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7f6c41883c8a974e75d2bccbc15fce8140a18a2f;p=dbsrgits%2FDBIx-Class.git

Copy the working mk_hash from HashRefInflator in -current into Cookbook
---

diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod
index 7806b08..8f098af 100644
--- a/lib/DBIx/Class/Manual/Cookbook.pod
+++ b/lib/DBIx/Class/Manual/Cookbook.pod
@@ -1172,8 +1172,26 @@ C<inflate_result>:
   sub mk_hash {
      my ($me, $rest) = @_;
 
-     return { %$me, 
-        map { ($_ => mk_hash(@{$rest->{$_}})) } keys %$rest
+     # to avoid emtpy has_many rels contain one empty hashref
+     return if (not keys %$me);
+
+     my $def;
+
+     foreach (values %$me) {
+         if (defined $_) {
+             $def = 1;
+             last;
+         }
+     }
+     return unless $def;
+
+     return { %$me,
+         map {
+           ( $_ =>
+              ref($rest->{$_}[0]) eq 'ARRAY' ? [ map { mk_hash(@$_) } @{$rest->{$_}} ]
+                                             : mk_hash( @{$rest->{$_}} )
+           )
+         } keys %$rest
      };
   }