diff --git a/lib/Doctrine/Connection/UnitOfWork.php b/lib/Doctrine/Connection/UnitOfWork.php index e36179f93..7d451b974 100644 --- a/lib/Doctrine/Connection/UnitOfWork.php +++ b/lib/Doctrine/Connection/UnitOfWork.php @@ -611,6 +611,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module $rootRecord->merge($dataSet[$parent]); $this->processSingleInsert($rootRecord); + + $record->assignIdentifier($rootRecord->identifier()); } else { foreach ((array) $rootRecord->identifier() as $id => $value) { $dataSet[$parent][$id] = $value; diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 56bdb239b..6fef35ad4 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -1443,11 +1443,18 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count $this->_state = Doctrine_Record::STATE_CLEAN; $this->_modified = array(); } else { - $name = $this->_table->getIdentifier(); - $this->_id[$name] = $id; - $this->_data[$name] = $id; - $this->_state = Doctrine_Record::STATE_CLEAN; - $this->_modified = array(); + if (is_array($id)) { + foreach ($id as $fieldName => $value) { + $this->_id[$fieldName] = $value; + $this->_data[$fieldName] = $value; + } + } else { + $name = $this->_table->getIdentifier(); + $this->_id[$name] = $id; + $this->_data[$name] = $id; + } + $this->_state = Doctrine_Record::STATE_CLEAN; + $this->_modified = array(); } } diff --git a/tests/Ticket/697TestCase.php b/tests/Ticket/697TestCase.php new file mode 100644 index 000000000..547cb641d --- /dev/null +++ b/tests/Ticket/697TestCase.php @@ -0,0 +1,53 @@ +tables = array('T697_Person', 'T697_User'); + parent::prepareTables(); + } + + public function testIdsAreSetWhenSavingSubclassInstancesInCTI() + { + $p = new T697_Person(); + $p['name']='Rodrigo'; + $p->save(); + $this->assertEqual(1, $p->id); + + $u = new T697_User(); + $u['name']='Fernandes'; + $u['password']='Doctrine RULES'; + $u->save(); + $this->assertEqual(2, $u->id); + } +} + +class T697_Person extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('name', 'string', 30); + } +} + +//Class table inheritance +class T697_User extends T697_Person { + public function setTableDefinition() + { + $this->hasColumn('password', 'string', 30); + } +} diff --git a/tests/run.php b/tests/run.php index 6d638f6ef..ba3479a17 100644 --- a/tests/run.php +++ b/tests/run.php @@ -25,6 +25,7 @@ $tickets->addTestCase(new Doctrine_Ticket_438_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_638_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_673_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_626D_TestCase()); +$tickets->addTestCase(new Doctrine_Ticket_697_TestCase()); $test->addTestCase($tickets); // Connection drivers (not yet fully tested)