[Solar-svn] Revision 3117

pmjones at solarphp.com pmjones at solarphp.com
Mon Apr 14 15:46:25 CDT 2008


Solar_Sql_Model: [FIX] In method newRecord(), when single-table inheritance is invoked, tell the inherited record object to use the **inherited model**, not the current model.


Modified: trunk/Solar/Sql/Model.php
===================================================================
--- trunk/Solar/Sql/Model.php	2008-04-13 18:38:27 UTC (rev 3116)
+++ trunk/Solar/Sql/Model.php	2008-04-14 20:46:23 UTC (rev 3117)
@@ -1378,6 +1378,9 @@
      */
     public function newRecord($data)
     {
+        // the model object to use -- might get overridden by inheritance
+        $model = $this;
+        
         // the record class we'll use
         $class = null;
         
@@ -1389,13 +1392,22 @@
             $inherit = trim($data[$this->_inherit_col]);
         }
         
-        // did we find an inheritance?
+        // did we find an inheritance value?
         if ($inherit) {
-            // try to find a class based on inheritance, going up the stack
-            // as needed. this checks for Current_Model_Type,
-            // Parent_Model_Type, Grandparent_Model_Type, etc.
-            // suppress exceptions.
-            //
+            // try to find a model class based on inheritance, going up the
+            // stack as needed. this checks for Current_Model_Type,
+            // Parent_Model_Type, Grandparent_Model_Type, etc.  blow up if we
+            // can't find it.
+            $model_class = $this->_stack->load($inherit);
+            
+            // if different from the current class, reset the model object.
+            if ($model_class != $this->_class) {
+                // use the inherited model class, it's different from the
+                // current model
+                $model = Solar::factory($model_class, array($this->_config));
+            }
+            
+            // now we need the inherited record class.  suppress exceptions.
             // note that $class could still end up false, as we might not find
             // a related class in the hierarchy.
             $class = $this->_stack->load($inherit . '_Record', false);
@@ -1411,9 +1423,10 @@
             $class = $this->_record_class;
         }
         
-        // factory the appropriate record class, load it, and return it.
+        // factory the appropriate record class, set the model for it, then
+        // load and return it.
         $record = Solar::factory($class);
-        $record->setModel($this);
+        $record->setModel($model);
         $record->load($data);
         $record->setStatus('clean');
         return $record;




More information about the Solar-svn mailing list