[Solar-svn] Revision 2782

pmjones at solarphp.com pmjones at solarphp.com
Mon Sep 24 10:25:49 CDT 2007


branch: Solar_Sql_Model_Collection: 

* [ADD] Added _preDelete() and _postDelete() hooks

* [FIX] Method save() now instantiates each record as it goes to call save() on it




Modified: branches/orm/Solar/Sql/Model/Collection.php
===================================================================
--- branches/orm/Solar/Sql/Model/Collection.php	2007-09-24 15:21:08 UTC (rev 2781)
+++ branches/orm/Solar/Sql/Model/Collection.php	2007-09-24 15:25:48 UTC (rev 2782)
@@ -131,8 +131,8 @@
         // pre-logic
         $this->_preSave();
         
-        // next, saves
-        foreach($this->_data as $record) {
+        // save, instantiating each record
+        foreach ($this as $record) {
             $status = $record->getStatus();
             if ($status != 'deleted') {
                 $record->save();
@@ -151,16 +151,27 @@
     {
     }
     
+    // deletes each record in the collection
     public function delete()
     {
-        foreach ($this->_data as $record) {
+        $this->_preDelete();
+        foreach ($this as $record) {
             $status = $record->getStatus();
             if ($status != 'deleted') {
                 $record->delete();
             }
         }
+        $this->_postDelete();
     }
     
+    public function _preDelete()
+    {
+    }
+    
+    protected function _postDelete()
+    {
+    }
+    
     // -----------------------------------------------------------------
     //
     // Iterator
@@ -196,13 +207,8 @@
      */
     public function offsetGet($key)
     {
-        // don't return records that don't exist in the original data
-        if (empty($this->_data[$key])) {
-            return false;
-        }
-        
         // convert array to record object
-        // honors single-tabe inheritance
+        // honors single-table inheritance
         if (is_array($this->_data[$key])) {
             
             // convert the data array to an object.




More information about the Solar-svn mailing list