Merge branch 'DDC-832'
This commit is contained in:
commit
3936f179e9
@ -273,7 +273,10 @@ class BasicEntityPersister
|
||||
$updateData = $this->_prepareUpdateData($entity);
|
||||
$tableName = $this->_class->table['name'];
|
||||
if (isset($updateData[$tableName]) && $updateData[$tableName]) {
|
||||
$this->_updateTable($entity, $tableName, $updateData[$tableName], $this->_class->isVersioned);
|
||||
$this->_updateTable(
|
||||
$entity, $this->_class->getQuotedTableName($this->_platform),
|
||||
$updateData[$tableName], $this->_class->isVersioned
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,11 +285,11 @@ class BasicEntityPersister
|
||||
* The UPDATE can optionally be versioned, which requires the entity to have a version field.
|
||||
*
|
||||
* @param object $entity The entity object being updated.
|
||||
* @param string $tableName The name of the table to apply the UPDATE on.
|
||||
* @param string $quotedTableName The quoted name of the table to apply the UPDATE on.
|
||||
* @param array $updateData The map of columns to update (column => value).
|
||||
* @param boolean $versioned Whether the UPDATE should be versioned.
|
||||
*/
|
||||
protected final function _updateTable($entity, $tableName, array $updateData, $versioned = false)
|
||||
protected final function _updateTable($entity, $quotedTableName, array $updateData, $versioned = false)
|
||||
{
|
||||
$set = $params = $types = array();
|
||||
|
||||
@ -322,7 +325,7 @@ class BasicEntityPersister
|
||||
$types[] = $this->_class->fieldMappings[$versionField]['type'];
|
||||
}
|
||||
|
||||
$sql = "UPDATE $tableName SET " . implode(', ', $set)
|
||||
$sql = "UPDATE $quotedTableName SET " . implode(', ', $set)
|
||||
. ' WHERE ' . implode(' = ? AND ', $where) . ' = ?';
|
||||
|
||||
$result = $this->_conn->executeUpdate($sql, $params, $types);
|
||||
@ -386,7 +389,7 @@ class BasicEntityPersister
|
||||
$this->deleteJoinTableRecords($identifier);
|
||||
|
||||
$id = array_combine($this->_class->getIdentifierColumnNames(), $identifier);
|
||||
$this->_conn->delete($this->_class->table['name'], $id);
|
||||
$this->_conn->delete($this->_class->getQuotedTableName($this->_platform), $id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -35,9 +35,18 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
/**
|
||||
* Map that maps column names to the table names that own them.
|
||||
* This is mainly a temporary cache, used during a single request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_owningTableMap = array();
|
||||
|
||||
/**
|
||||
* Map of table to quoted table names.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_quotedTableMap = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -74,18 +83,16 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
*/
|
||||
public function getOwningTable($fieldName)
|
||||
{
|
||||
if ( ! isset($this->_owningTableMap[$fieldName])) {
|
||||
if (!isset($this->_owningTableMap[$fieldName])) {
|
||||
if (isset($this->_class->associationMappings[$fieldName]['inherited'])) {
|
||||
$this->_owningTableMap[$fieldName] = $this->_em->getClassMetadata(
|
||||
$this->_class->associationMappings[$fieldName]['inherited']
|
||||
)->table['name'];
|
||||
$cm = $this->_em->getClassMetadata($this->_class->associationMappings[$fieldName]['inherited']);
|
||||
} else if (isset($this->_class->fieldMappings[$fieldName]['inherited'])) {
|
||||
$this->_owningTableMap[$fieldName] = $this->_em->getClassMetadata(
|
||||
$this->_class->fieldMappings[$fieldName]['inherited']
|
||||
)->table['name'];
|
||||
$cm = $this->_em->getClassMetadata($this->_class->fieldMappings[$fieldName]['inherited']);
|
||||
} else {
|
||||
$this->_owningTableMap[$fieldName] = $this->_class->table['name'];
|
||||
$cm = $this->_class;
|
||||
}
|
||||
$this->_owningTableMap[$fieldName] = $cm->table['name'];
|
||||
$this->_quotedTableMap[$cm->table['name']] = $cm->getQuotedTableName($this->_platform);
|
||||
}
|
||||
|
||||
return $this->_owningTableMap[$fieldName];
|
||||
@ -191,12 +198,12 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
|
||||
if ($updateData) {
|
||||
foreach ($updateData as $tableName => $data) {
|
||||
$this->_updateTable($entity, $tableName, $data, $isVersioned && $versionedTable == $tableName);
|
||||
$this->_updateTable($entity, $this->_quotedTableMap[$tableName], $data, $isVersioned && $versionedTable == $tableName);
|
||||
}
|
||||
// Make sure the table with the version column is updated even if no columns on that
|
||||
// table were affected.
|
||||
if ($isVersioned && ! isset($updateData[$versionedTable])) {
|
||||
$this->_updateTable($entity, $versionedTable, array(), true);
|
||||
$this->_updateTable($entity, $this->_quotedTableMap[$versionedTable], array(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
178
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php
Normal file
178
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php
Normal file
@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||
use Doctrine\Tests\Models\CMS\CmsGroup;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
class DDC832Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
try {
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832JoinedIndex'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832JoinedTreeIndex'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832Like'),
|
||||
));
|
||||
} catch(\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-832
|
||||
*/
|
||||
public function testQuotedTableBasicUpdate()
|
||||
{
|
||||
$like = new DDC832Like("test");
|
||||
$this->_em->persist($like);
|
||||
$this->_em->flush();
|
||||
|
||||
$like->word = "test2";
|
||||
$this->_em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-832
|
||||
*/
|
||||
public function testQuotedTableBasicRemove()
|
||||
{
|
||||
$like = new DDC832Like("test");
|
||||
$this->_em->persist($like);
|
||||
$this->_em->flush();
|
||||
|
||||
$this->_em->remove($like);
|
||||
$this->_em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-832
|
||||
*/
|
||||
public function testQuotedTableJoinedUpdate()
|
||||
{
|
||||
$index = new DDC832JoinedIndex("test");
|
||||
$this->_em->persist($index);
|
||||
$this->_em->flush();
|
||||
|
||||
$index->name = "asdf";
|
||||
$this->_em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-832
|
||||
*/
|
||||
public function testQuotedTableJoinedRemove()
|
||||
{
|
||||
$index = new DDC832JoinedIndex("test");
|
||||
$this->_em->persist($index);
|
||||
$this->_em->flush();
|
||||
|
||||
$this->_em->remove($index);
|
||||
$this->_em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-832
|
||||
*/
|
||||
public function testQuotedTableJoinedChildUpdate()
|
||||
{
|
||||
$index = new DDC832JoinedTreeIndex("test", 1, 2);
|
||||
$this->_em->persist($index);
|
||||
$this->_em->flush();
|
||||
|
||||
$index->name = "asdf";
|
||||
$this->_em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-832
|
||||
*/
|
||||
public function testQuotedTableJoinedChildRemove()
|
||||
{
|
||||
$index = new DDC832JoinedTreeIndex("test", 1, 2);
|
||||
$this->_em->persist($index);
|
||||
$this->_em->flush();
|
||||
|
||||
$this->_em->remove($index);
|
||||
$this->_em->flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="`LIKE`")
|
||||
*/
|
||||
class DDC832Like
|
||||
{
|
||||
/**
|
||||
* @Id @Column(type="integer") @GeneratedValue
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/** @Column(type="string") */
|
||||
public $word;
|
||||
|
||||
/**
|
||||
* @version
|
||||
* @Column(type="integer")
|
||||
*/
|
||||
public $version;
|
||||
|
||||
public function __construct($word)
|
||||
{
|
||||
$this->word = $word;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="`INDEX`")
|
||||
* @InheritanceType("JOINED")
|
||||
* @DiscriminatorColumn(name="discr", type="string")
|
||||
* @DiscriminatorMap({"like" = "DDC832JoinedIndex", "fuzzy" = "DDC832JoinedTreeIndex"})
|
||||
*/
|
||||
class DDC832JoinedIndex
|
||||
{
|
||||
/**
|
||||
* @Id @Column(type="integer") @GeneratedValue
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/** @Column(type="string") */
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @version
|
||||
* @Column(type="integer")
|
||||
*/
|
||||
public $version;
|
||||
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="`TREE_INDEX`")
|
||||
*/
|
||||
class DDC832JoinedTreeIndex extends DDC832JoinedIndex
|
||||
{
|
||||
/** @Column(type="integer") */
|
||||
public $lft;
|
||||
/** @Column(type="integer") */
|
||||
public $rgt;
|
||||
|
||||
public function __construct($name, $lft, $rgt)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->lft = $lft;
|
||||
$this->rgt = $rgt;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user