[Solar-svn] Revision 2783

pmjones at solarphp.com pmjones at solarphp.com
Mon Sep 24 10:27:57 CDT 2007


branch: Solar_Sql_Model_Record: [FIX] In method save(), when saving related records, check empty() against $this->_data[$name] instead of $this->$name to avoid lazy-loading related records (which in turn causes infinite recursion)



Modified: branches/orm/Solar/Sql/Model/Record.php
===================================================================
--- branches/orm/Solar/Sql/Model/Record.php	2007-09-24 15:25:48 UTC (rev 2782)
+++ branches/orm/Solar/Sql/Model/Record.php	2007-09-24 15:27:56 UTC (rev 2783)
@@ -514,15 +514,18 @@
         
         // now save each related, but only if instantiated
         foreach ($this->_model->related as $name => $info) {
-            if (empty($this->$name)) {
-                // skip empty
+            
+            // use $this->_data[$name] **instead of** $this->$name,
+            // to avoid lazy-loading the related record (which in turn
+            // causes infinite recursion)
+            if (empty($this->_data[$name])) {
                 continue;
             }
             
-            if ($this->$name instanceof Solar_Sql_Model_Record ||
-                $this->$name instanceof Solar_Sql_Model_Collection) {
+            if ($this->_data[$name] instanceof Solar_Sql_Model_Record ||
+                $this->_data[$name] instanceof Solar_Sql_Model_Collection) {
                 // is a record or collection, save them
-                $this->$name->save();
+                $this->_data[$name]->save();
             }
         }
     }




More information about the Solar-svn mailing list