diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index 4027d40f5..4989c7919 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -245,11 +245,13 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister // Make sure the table with the version column is updated even if no columns on that // table were affected. - if ($isVersioned && ! isset($updateData[$versionedTable])) { - $tableName = $this->quoteStrategy->getTableName($versionedClass, $this->platform); + if ($isVersioned) { + if ( ! isset($updateData[$versionedTable])) { + $tableName = $this->quoteStrategy->getTableName($versionedClass, $this->platform); + $this->updateTable($entity, $tableName, array(), true); + } + $identifiers = $this->em->getUnitOfWork()->getEntityIdentifier($entity); - - $this->updateTable($entity, $tableName, array(), true); $this->assignDefaultVersionValue($entity, $identifiers); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php new file mode 100644 index 000000000..178685b39 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php @@ -0,0 +1,62 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2175Entity'), + )); + } + + public function testIssue() + { + $entity = new DDC2175Entity(); + $entity->field = "foo"; + + $this->_em->persist($entity); + $this->_em->flush(); + + $this->assertEquals(1, $entity->version); + + $entity->field = "bar"; + $this->_em->flush(); + + $this->assertEquals(2, $entity->version); + + $entity->field = "baz"; + $this->_em->flush(); + + $this->assertEquals(3, $entity->version); + } +} + +/** + * @Entity + * @InheritanceType("JOINED") + * @DiscriminatorMap({"entity": "DDC2175Entity"}) + */ +class DDC2175Entity +{ + /** + * @Id @GeneratedValue @Column(type="integer") + */ + public $id; + + /** + * @Column(type="string") + */ + public $field; + + /** + * @Version + * @Column(type="integer") + */ + public $version; +}