[Solar-svn] Revision 2755

pmjones at solarphp.com pmjones at solarphp.com
Mon Sep 17 09:09:42 CDT 2007


branch Solar_Sql_Model_Record: [CHG] In the toArray() method, if the value is a has-many relation but has no records, use an empty array instead of a null value.


Modified: branches/orm/Solar/Sql/Model/Record.php
===================================================================
--- branches/orm/Solar/Sql/Model/Record.php	2007-09-17 14:08:01 UTC (rev 2754)
+++ branches/orm/Solar/Sql/Model/Record.php	2007-09-17 14:09:41 UTC (rev 2755)
@@ -399,11 +399,23 @@
         // get a copy of each data element
         $data = array();
         foreach ($clone as $key => $val) {
+            // get the sub-value
             if ($val instanceof Solar_Sql_Model_Record) {
-                $data[$key] = $val->toArray();
+                $sub = $val->toArray();
             } else {
-                $data[$key] = $val;
+                $sub = $val;
             }
+            
+            // if the sub-value is a has-many but is empty, convert to an
+            // array
+            if (empty($sub) && ! empty($this->_model->related[$key]) &&
+                $this->_model->related[$key]['type'] == 'has_many') {
+                // convert from null to array
+                $sub = array();
+            }
+            
+            // keep the sub-value
+            $data[$key] = $sub;
         }
         
         // done!




More information about the Solar-svn mailing list