Fix DDC-795 (subtask of DDC-117) and integrated a test for cascade (that only works with sequence id generators).
This commit is contained in:
parent
e7b4dca611
commit
337e2fa043
@ -913,7 +913,22 @@ class BasicEntityPersister
|
||||
$columnList .= $this->_getSelectColumnSQL($field, $this->_class);
|
||||
}
|
||||
|
||||
$this->_selectColumnListSql = $columnList . $this->_getSelectJoinColumnsSQL($this->_class);
|
||||
foreach ($this->_class->associationMappings as $assoc) {
|
||||
if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) {
|
||||
foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) {
|
||||
if ($columnList) $columnList .= ', ';
|
||||
|
||||
$columnAlias = $srcColumn . $this->_sqlAliasCounter++;
|
||||
$columnList .= $this->_getSQLTableAlias($this->_class->name) . ".$srcColumn AS $columnAlias";
|
||||
$resultColumnName = $this->_platform->getSQLResultCasing($columnAlias);
|
||||
if ( ! isset($this->_resultColumnNames[$resultColumnName])) {
|
||||
$this->_resultColumnNames[$resultColumnName] = $srcColumn;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_selectColumnListSql = $columnList;
|
||||
|
||||
return $this->_selectColumnListSql;
|
||||
}
|
||||
@ -1026,33 +1041,6 @@ class BasicEntityPersister
|
||||
return "$sql AS $columnAlias";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SQL snippet for all join columns of the given class that are to be
|
||||
* placed in an SQL SELECT statement.
|
||||
*
|
||||
* @param $class
|
||||
* @return string
|
||||
* @todo Not reused... inline?
|
||||
*/
|
||||
private function _getSelectJoinColumnsSQL(ClassMetadata $class)
|
||||
{
|
||||
$sql = '';
|
||||
foreach ($class->associationMappings as $assoc) {
|
||||
if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) {
|
||||
foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) {
|
||||
$columnAlias = $srcColumn . $this->_sqlAliasCounter++;
|
||||
$sql .= ', ' . $this->_getSQLTableAlias($this->_class->name) . ".$srcColumn AS $columnAlias";
|
||||
$resultColumnName = $this->_platform->getSQLResultCasing($columnAlias);
|
||||
if ( ! isset($this->_resultColumnNames[$resultColumnName])) {
|
||||
$this->_resultColumnNames[$resultColumnName] = $srcColumn;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SQL table alias for the given class name.
|
||||
*
|
||||
|
@ -234,6 +234,23 @@ class DDC117Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$article = $this->_em->find(get_class($this->article1), $this->article1->id());
|
||||
$this->assertEquals('not so very long text!', $article->getText());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-117
|
||||
*/
|
||||
public function testOneToOneCascadePersist()
|
||||
{
|
||||
if (!$this->_em->getConnection()->getDatabasePlatform()->prefersSequences()) {
|
||||
$this->markTestSkipped('Test only works with databases that prefer sequences as ID strategy.');
|
||||
}
|
||||
|
||||
$this->article1 = new DDC117Article("Foo");
|
||||
|
||||
$this->articleDetails = new DDC117ArticleDetails($this->article1, "Very long text");
|
||||
|
||||
$this->_em->persist($this->article1);
|
||||
$this->_em->flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -252,7 +269,7 @@ class DDC117Article
|
||||
private $references;
|
||||
|
||||
/**
|
||||
* @OneToOne(targetEntity="DDC117ArticleDetails", mappedBy="article")
|
||||
* @OneToOne(targetEntity="DDC117ArticleDetails", mappedBy="article", cascade={"persist"})
|
||||
*/
|
||||
private $details;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user