[2.0][DDC-448][DDC-513] Fixed issue with Joined Inheritance Type and One To One Associations.
This commit is contained in:
parent
b6f9cd0c07
commit
56a8f5cd53
@ -465,6 +465,11 @@ class SqlWalker implements TreeWalker
|
|||||||
$fieldName = array_pop($parts);
|
$fieldName = array_pop($parts);
|
||||||
$dqlAlias = $pathExpr->identificationVariable;
|
$dqlAlias = $pathExpr->identificationVariable;
|
||||||
$class = $this->_queryComponents[$dqlAlias]['metadata'];
|
$class = $this->_queryComponents[$dqlAlias]['metadata'];
|
||||||
|
|
||||||
|
if (isset($class->inheritedAssociationFields[$fieldName])) {
|
||||||
|
$class = $this->_em->getClassMetadata($class->inheritedAssociationFields[$fieldName]);
|
||||||
|
}
|
||||||
|
|
||||||
$assoc = $class->associationMappings[$fieldName];
|
$assoc = $class->associationMappings[$fieldName];
|
||||||
|
|
||||||
if ($assoc->isOwningSide) {
|
if ($assoc->isOwningSide) {
|
||||||
@ -472,8 +477,8 @@ class SqlWalker implements TreeWalker
|
|||||||
if (count($assoc->sourceToTargetKeyColumns) > 1) {
|
if (count($assoc->sourceToTargetKeyColumns) > 1) {
|
||||||
throw QueryException::associationPathCompositeKeyNotSupported();
|
throw QueryException::associationPathCompositeKeyNotSupported();
|
||||||
}
|
}
|
||||||
$sql .= $this->walkIdentificationVariable($dqlAlias) . '.'
|
$sql .= $this->getSqlTableAlias($class->table['name'], $dqlAlias) . '.'
|
||||||
. reset($assoc->targetToSourceKeyColumns);
|
. reset($assoc->targetToSourceKeyColumns);
|
||||||
} else {
|
} else {
|
||||||
// 2- Inverse side: NOT (YET?) SUPPORTED
|
// 2- Inverse side: NOT (YET?) SUPPORTED
|
||||||
throw QueryException::associationPathInverseSideNotSupported();
|
throw QueryException::associationPathInverseSideNotSupported();
|
||||||
@ -683,23 +688,15 @@ class SqlWalker implements TreeWalker
|
|||||||
|
|
||||||
$joinAssocPathExpr = $join->joinAssociationPathExpression;
|
$joinAssocPathExpr = $join->joinAssociationPathExpression;
|
||||||
$joinedDqlAlias = $join->aliasIdentificationVariable;
|
$joinedDqlAlias = $join->aliasIdentificationVariable;
|
||||||
$targetQComp = $this->_queryComponents[$joinedDqlAlias];
|
$relation = $this->_queryComponents[$joinedDqlAlias]['relation'];
|
||||||
$targetClass = $targetQComp['metadata'];
|
$targetClass = $this->_em->getClassMetadata($relation->targetEntityName);
|
||||||
$relation = $targetQComp['relation'];
|
$sourceClass = $this->_em->getClassMetadata($relation->sourceEntityName);
|
||||||
$sourceClass = $this->_queryComponents[$joinAssocPathExpr->identificationVariable]['metadata'];
|
|
||||||
|
|
||||||
$targetTableName = $targetClass->getQuotedTableName($this->_platform);
|
$targetTableName = $targetClass->getQuotedTableName($this->_platform);
|
||||||
$targetTableAlias = $this->getSqlTableAlias($targetClass->getTableName(), $joinedDqlAlias);
|
$targetTableAlias = $this->getSqlTableAlias($targetClass->table['name'], $joinedDqlAlias);
|
||||||
$sourceTableAlias = $this->getSqlTableAlias(
|
$sourceTableAlias = $this->getSqlTableAlias($sourceClass->table['name'], $joinAssocPathExpr->identificationVariable);
|
||||||
$sourceClass->getTableName(), $joinAssocPathExpr->identificationVariable
|
|
||||||
);
|
|
||||||
|
|
||||||
// Ensure we got the owning side, since it has all mapping info
|
// Ensure we got the owning side, since it has all mapping info
|
||||||
if ( ! $relation->isOwningSide) {
|
$assoc = ( ! $relation->isOwningSide) ? $targetClass->associationMappings[$relation->mappedBy] : $relation;
|
||||||
$assoc = $targetClass->associationMappings[$relation->mappedBy];
|
|
||||||
} else {
|
|
||||||
$assoc = $relation;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->_query->getHint(Query::HINT_INTERNAL_ITERATION) == true) {
|
if ($this->_query->getHint(Query::HINT_INTERNAL_ITERATION) == true) {
|
||||||
if ($relation->isOneToMany() || $relation->isManyToMany()) {
|
if ($relation->isOneToMany() || $relation->isManyToMany()) {
|
||||||
@ -713,7 +710,7 @@ class SqlWalker implements TreeWalker
|
|||||||
|
|
||||||
foreach ($assoc->sourceToTargetKeyColumns as $sourceColumn => $targetColumn) {
|
foreach ($assoc->sourceToTargetKeyColumns as $sourceColumn => $targetColumn) {
|
||||||
if ( ! $first) $sql .= ' AND '; else $first = false;
|
if ( ! $first) $sql .= ' AND '; else $first = false;
|
||||||
|
|
||||||
if ($relation->isOwningSide) {
|
if ($relation->isOwningSide) {
|
||||||
$quotedTargetColumn = $targetClass->getQuotedColumnName($targetClass->fieldNames[$targetColumn], $this->_platform);
|
$quotedTargetColumn = $targetClass->getQuotedColumnName($targetClass->fieldNames[$targetColumn], $this->_platform);
|
||||||
$sql .= $sourceTableAlias . '.' . $sourceColumn
|
$sql .= $sourceTableAlias . '.' . $sourceColumn
|
||||||
|
71
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php
Normal file
71
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../../TestInit.php';
|
||||||
|
|
||||||
|
class DDC448Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
|
{
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->_schemaTool->createSchema(array(
|
||||||
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC448MainTable'),
|
||||||
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC448ConnectedClass'),
|
||||||
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC448SubTable'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIssue()
|
||||||
|
{
|
||||||
|
$q = $this->_em->createQuery("select b from ".__NAMESPACE__."\\DDC448SubTable b where b.connectedClassId = ?1");
|
||||||
|
$this->assertEquals('SELECT d0_.id AS id0, d0_.discr AS discr1, d0_.connectedClassId AS connectedClassId2 FROM SubTable s1_ INNER JOIN DDC448MainTable d0_ ON s1_.id = d0_.id WHERE d0_.connectedClassId = ?', $q->getSQL());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
* @InheritanceType("JOINED")
|
||||||
|
* @DiscriminatorColumn(name="discr", type="smallint")
|
||||||
|
* @DiscriminatorMap({
|
||||||
|
* "0" = "DDC448MainTable",
|
||||||
|
* "1" = "DDC448SubTable"
|
||||||
|
* })
|
||||||
|
*/
|
||||||
|
class DDC448MainTable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @Column(name="id", type="integer")
|
||||||
|
* @GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ManyToOne(targetEntity="DDC448ConnectedClass", cascade={"all"}, fetch="EAGER")
|
||||||
|
* @JoinColumn(name="connectedClassId", referencedColumnName="id", onDelete="CASCADE", onUpdate="CASCADE", nullable=true)
|
||||||
|
*/
|
||||||
|
private $connectedClassId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
* @Table(name="connectedClass")
|
||||||
|
* @HasLifecycleCallbacks
|
||||||
|
*/
|
||||||
|
class DDC448ConnectedClass
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @Column(name="id", type="integer")
|
||||||
|
* @GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
protected $id; // connected with DDC448MainTable
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
* @Table(name="SubTable")
|
||||||
|
*/
|
||||||
|
class DDC448SubTable extends DDC448MainTable
|
||||||
|
{
|
||||||
|
}
|
79
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC513Test.php
Normal file
79
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC513Test.php
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../../TestInit.php';
|
||||||
|
|
||||||
|
class DDC513Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
|
{
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->_schemaTool->createSchema(array(
|
||||||
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC513OfferItem'),
|
||||||
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC513Item'),
|
||||||
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC513Price'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIssue()
|
||||||
|
{
|
||||||
|
$item = new DDC513OfferItem();
|
||||||
|
$this->_em->persist($item);
|
||||||
|
$this->_em->flush();
|
||||||
|
|
||||||
|
//$q = $this->_em->createQuery("select u from ".__NAMESPACE__."\\DDC513Item u left join u.price p");
|
||||||
|
//$this->assertEquals('SELECT d0_.id AS id0, d0_.discr AS discr1, d0_.price AS price2 FROM DDC513Item d0_ LEFT JOIN DDC513OfferItem d1_ ON d0_.id = d1_.id LEFT JOIN DDC513Price d2_ ON d0_.price = d2_.id', $q->getSQL());
|
||||||
|
|
||||||
|
/* THIS QUERY CAUSE EXCEPTION */
|
||||||
|
$q = $this->_em->createQuery("select u from ".__NAMESPACE__."\\DDC513OfferItem u left join u.price p");
|
||||||
|
$this->assertEquals('SELECT d0_.id AS id0, d0_.discr AS discr1, d0_.price AS price2 FROM DDC513OfferItem d1_ INNER JOIN DDC513Item d0_ ON d1_.id = d0_.id LEFT JOIN DDC513Price d2_ ON d0_.price = d2_.id', $q->getSQL());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class DDC513OfferItem extends DDC513Item
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
* @InheritanceType("JOINED")
|
||||||
|
* @DiscriminatorColumn(name="discr", type="string")
|
||||||
|
* @DiscriminatorMap({"item" = "DDC513Item", "offerItem" = "DDC513OfferItem"})
|
||||||
|
*/
|
||||||
|
class DDC513Item
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @Column(type="integer")
|
||||||
|
* @GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
public $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @OneToOne(targetEntity="DDC513Price", cascade={"remove","persist"})
|
||||||
|
* @JoinColumn(name="price", referencedColumnName="id")
|
||||||
|
*/
|
||||||
|
public $price;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class DDC513Price {
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @Column(type="integer")
|
||||||
|
* @GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
public $id;
|
||||||
|
|
||||||
|
/** @Column(type="string") */
|
||||||
|
public $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user