From: avl Date: Sun, 5 Oct 2008 17:48:23 +0000 (+0300) Subject: Support ManyToMany relations in forms X-Git-Tag: 0.6~170 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=19744c86a5862e67981b6446a95d9d76e4806002;p=ipf-legacy-orm.git Support ManyToMany relations in forms --- diff --git a/ipf/orm/connection/unitofwork.php b/ipf/orm/connection/unitofwork.php index abeb5fe..887fa5d 100644 --- a/ipf/orm/connection/unitofwork.php +++ b/ipf/orm/connection/unitofwork.php @@ -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() . ' = ?' diff --git a/ipf/orm/exception/orm.php b/ipf/orm/exception/orm.php index 12b42aa..e57b5d5 100644 --- a/ipf/orm/exception/orm.php +++ b/ipf/orm/exception/orm.php @@ -1,7 +1,6 @@ 'unknown error', IPF_ORM::ERR_ALREADY_EXISTS => 'already exists', @@ -49,6 +48,6 @@ class IPF_ORM_Exception extends IPF_Exception_Base{ } - - - + + + diff --git a/ipf/orm/record.php b/ipf/orm/record.php index deea2c9..3eef7b0 100644 --- a/ipf/orm/record.php +++ b/ipf/orm/record.php @@ -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