]> git.andy128k.dev Git - ipf-legacy-orm.git/commitdiff
Support ManyToMany relations in forms
authoravl <alex.litovchenko@gmail.com>
Sun, 5 Oct 2008 17:48:23 +0000 (20:48 +0300)
committeravl <alex.litovchenko@gmail.com>
Sun, 5 Oct 2008 17:48:23 +0000 (20:48 +0300)
ipf/orm/connection/unitofwork.php
ipf/orm/exception/orm.php
ipf/orm/record.php

index abeb5feb2676fa439dcdd61ba967a88356ebcbf6..887fa5d29758f1aabd31ce49b32d2e484db779dc 100644 (file)
@@ -23,7 +23,7 @@ class IPF_ORM_Connection_UnitOfWork extends IPF_ORM_Connection_Module
             $record->preSave($event);
             $record->getTable()->getRecordListener()->preSave($event);
             $state = $record->state();
-            
+
             if ( ! $event->skipOperation) {
                 switch ($state) {
                     case IPF_ORM_Record::STATE_TDIRTY:
@@ -59,7 +59,6 @@ class IPF_ORM_Connection_UnitOfWork extends IPF_ORM_Connection_Module
 
             if ($record->hasReference($alias)) {
                 $obj = $record->$alias;
-
                 // check that the related object is not an instance of IPF_ORM_Null
                 if ( ! ($obj instanceof IPF_ORM_Null)) {
                     $obj->save($conn);
@@ -71,7 +70,6 @@ class IPF_ORM_Connection_UnitOfWork extends IPF_ORM_Connection_Module
         $this->saveAssociations($record);
 
         $record->state($state);
-
         $conn->commit();
 
         return true;
@@ -294,11 +292,12 @@ class IPF_ORM_Connection_UnitOfWork extends IPF_ORM_Connection_Module
     {
         foreach ($record->getReferences() as $k => $v) {
             $rel = $record->getTable()->getRelation($k);
-
+            //print get_class($rel);
             if ($rel instanceof IPF_ORM_Relation_Association) {
                 $v->save($this->conn);
 
                 $assocTable = $rel->getAssociationTable();
+
                 foreach ($v->getDeleteDiff() as $r) {
                     $query = 'DELETE FROM ' . $assocTable->getTableName()
                            . ' WHERE ' . $rel->getForeign() . ' = ?'
index 12b42aa810e9ef314c83a17dee613a888f8a8658..e57b5d5c81ca27ab6c34dc573af511c2bab4f2b4 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 
 class IPF_ORM_Exception extends IPF_Exception_Base{
-{ 
     protected static $_errorMessages = array(
         IPF_ORM::ERR                    => 'unknown error',
         IPF_ORM::ERR_ALREADY_EXISTS     => 'already exists',
@@ -49,6 +48,6 @@ class IPF_ORM_Exception extends IPF_Exception_Base{
 
 }
 
-    
-    
-    
+
+
+
index deea2c9af436a7840a5b3b5bb33e3b7e18fec481..3eef7b0be8a9563bfbc1961db28c956c0a012c64 100644 (file)
@@ -1259,6 +1259,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
 
     public function SetFromFormData($cleaned_values)
     {
+        $names = $this->_table->getFieldNames();
         foreach ($cleaned_values as $key=>$val) {
             $validators = $this->getTable()->getFieldValidators($key);
             if (
@@ -1269,7 +1270,8 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
                 if (($val!==null) && ($val==''))
                     continue;
             }
-            $this->$key = $val;
+            if (array_search($key,$names))
+                $this->$key = $val;
         }
     }
 }
\ No newline at end of file