Hello all,

I recently noticed a quite annoying bug with sfFormDoctrine ...
I've got a quite simple schema, in which I've got three classes : "Task",
"Category", and "TaskCategory" ; "Task" and "Category" relation type is n:m.

The problem is that, when I generate a crud to administrate Task objects,
TaskForm doesn't save the TaskCategory relation properly : the "task_id" and
"category_id" values of the TaskCategory object are "switched".

I mean that saving a Task object with id = 1 after having associed it with a
Category whose id = 5 will make Doctrine try to save a TaskCategory object
that will contain [task_id : 5, category_id : 1].

I join to this message the concerned part of the stacktrace I get when I try
to submit my form (exception is thrown here because I try to save a task
with id = 1 with a category whose id = 5. As the values are switch and as it
doesn't exist any task with id = 5, doctrine throws me an integrity
violation on the foreign key constraint).


Did anyone already notice this ?


Cheers,

Taku (sorry for my english)




StackTrace :


   - at *Doctrine_Connection_Statement->execute*(*array*('1', '5'))
   in *
   
SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php
   * line 1041 ... <http://kontei/frontend_dev.php/task/update/id/1#>
   1.         try {
         2.             if ( ! empty($params)) {
         3.                 $stmt = $this->prepare($query);
         4.                 $stmt->execute($params);
         5.
         6.                 return $stmt->rowCount();
         7.             } else {
      - at *Doctrine_Connection->exec*('INSERT INTO task_category
   (category_id, task_id) VALUES (?, ?)', *array*('1', '5'))
   in *
   
SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php
   * line 674 ... <http://kontei/frontend_dev.php/task/update/id/1#>
   1.                 . ' (' . implode(', ', $cols) . ')'
         2.                 . ' VALUES (' . implode(', ', $a) . ')';
         3.
         4.         return $this->exec($query, array_values($fields));
         5.     }
         6.
         7.     /**
      - at *Doctrine_Connection->insert*(*object*('TaskCategoryTable'), *
   array*('category_id' => '1', 'task_id' => '5'))
   in *
   
SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php
   * line 600 ... <http://kontei/frontend_dev.php/task/update/id/1#>
   1.             $record->assignIdentifier($id);
         2.         }
         3.
         4.         $this->conn->insert($table, $fields);
         5.
         6.         if (empty($seq) && count($identifier) == 1 &&
         $identifier[0] == $table->getIdentifier() &&
         7.             $table->getIdentifierType() != Doctrine::
         IDENTIFIER_NATURAL) {
      - at *Doctrine_Connection_UnitOfWork->processSingleInsert*(*object*
   ('TaskCategory'))
   in *
   
SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php
   * line 559 ... <http://kontei/frontend_dev.php/task/update/id/1#>
   1.                     $this->_insertCTIRecord($table, $record);
         2.                     //--
         3.                 } else {
         4.                     $this->processSingleInsert($record);
         5.                 }
         6.             }
         7.
      - at *Doctrine_Connection_UnitOfWork->insert*(*object*
   ('TaskCategory'))
   in *
   
SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php
   * line 79 ... <http://kontei/frontend_dev.php/task/update/id/1#>
   1.                 switch ($state) {
         2.                     case Doctrine_Record::STATE_TDIRTY:
         3.                     case Doctrine_Record::STATE_TCLEAN:
         4.                         $isValid = $this->insert($record);
         5.                         break;
         6.                     case Doctrine_Record::STATE_DIRTY:
         7.                     case Doctrine_Record::STATE_PROXY:
      - at *Doctrine_Connection_UnitOfWork->saveGraph*(*object*
   ('TaskCategory'))
   in *
   
SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php
   * line 1318 ... <http://kontei/frontend_dev.php/task/update/id/1#>
   1.         if ($conn === null) {
         2.             $conn = $this->_table->getConnection();
         3.         }
         4.         $conn->unitOfWork->saveGraph($this);
         5.     }
         6.
         7.     /**
      - at *Doctrine_Record->save*()
   in *
   
SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php
   * line 2053 ... <http://kontei/frontend_dev.php/task/update/id/1#>
   1.                 $record = new $modelClassName;
         2.                 $record[$localFieldName] = $identifier;
         3.                 $record[$foreignFieldName] = $id;
         4.                 $record->save();
         5.             }
         6.
         7.         } else if ($rel instanceof Doctrine_Relation_ForeignKey) {

      - at *Doctrine_Record->link*('Categories', *array*('1', '5'))
   in *SF_ROOT_DIR/lib/form/doctrine/base/BaseTaskForm.class.php* line 128
   ... <http://kontei/frontend_dev.php/task/update/id/1#>
   1.     $values = $this->getValue('categories_list');
         2.     if (is_array($values))
         3.     {
         4.       $this->object->link('Categories', $values);
         5.     }
         6.   }
         7.
      - at *BaseTaskForm->saveCategoriesList*(*object*
   ('Doctrine_Connection_Mysql'))
   in *SF_ROOT_DIR/lib/form/doctrine/base/BaseTaskForm.class.php* line 75
   ... <http://kontei/frontend_dev.php/task/update/id/1#>
   1.     parent::doSave($con);
         2.
         3.     $this->saveUsersList($con);
         4.     $this->saveCategoriesList($con);
         5.   }
         6.
         7.   public function saveUsersList($con = null)
      - at *BaseTaskForm->doSave*(*object*('Doctrine_Connection_Mysql'))
   in *
   SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php
   * line 179 ... <http://kontei/frontend_dev.php/task/update/id/1#>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to