Skip to content

Commit

Permalink
Merge pull request #877 from aaronmu/DDC-1787
Browse files Browse the repository at this point in the history
Hotfix for DDC-1787
  • Loading branch information
Ocramius committed Dec 14, 2013
2 parents 5fa1b10 + 3cc6307 commit 6f1642b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php
Expand Up @@ -181,6 +181,10 @@ public function executeInserts()
$id = $this->em->getUnitOfWork()->getEntityIdentifier($entity);
}

if ($this->class->isVersioned) {
$this->assignDefaultVersionValue($entity, $id);
}

// Execute inserts on subtables.
// The order doesn't matter because all child tables link to the root table via FK.
foreach ($subTableStmts as $tableName => $stmt) {
Expand Down Expand Up @@ -212,10 +216,6 @@ public function executeInserts()
$stmt->closeCursor();
}

if ($this->class->isVersioned) {
$this->assignDefaultVersionValue($entity, $id);
}

$this->queuedInserts = array();

return $postInsertIds;
Expand Down
63 changes: 63 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php
@@ -0,0 +1,63 @@
<?php

namespace Doctrine\Tests\ORM\Functional\Ticket;

require_once __DIR__ . '/../../../TestInit.php';

/**
* @group DDC-1787
*/
class DDC1787Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1787Foo'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1787Bar'),
));
}

public function testIssue()
{
$bar = new DDC1787Bar;
$bar2 = new DDC1787Bar;

$this->_em->persist($bar);
$this->_em->persist($bar2);
$this->_em->flush();

$this->assertSame(1, $bar->getVersion());
}
}

/**
* @Entity
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({"bar" = "DDC1787Bar"})
*/
class DDC1787Foo
{
/**
* @Id @Column(type="integer") @GeneratedValue(strategy="AUTO")
*/
private $id;

/**
* @Version @Column(type="integer")
*/
private $version;

public function getVersion()
{
return $this->version;
}
}

/**
* @Entity
*/
class DDC1787Bar extends DDC1787Foo
{
}

0 comments on commit 6f1642b

Please sign in to comment.