[2.0][DDC-7] Fixed.
This commit is contained in:
parent
7ef91a6449
commit
3d3bcc1742
@ -295,7 +295,6 @@ final class PersistentCollection implements \Doctrine\Common\Collections\Collect
|
||||
return $this->_association;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Marks this collection as changed/dirty.
|
||||
*/
|
||||
|
@ -269,10 +269,9 @@ class JoinedSubclassPersister extends StandardEntityPersister
|
||||
*
|
||||
* @param array $criteria
|
||||
* @return string The SQL.
|
||||
* @todo Quote identifier.
|
||||
* @override
|
||||
*/
|
||||
protected function _getSelectEntitiesSql(array &$criteria)
|
||||
protected function _getSelectEntitiesSql(array &$criteria, $assoc = null)
|
||||
{
|
||||
$tableAliases = array();
|
||||
$aliasIndex = 1;
|
||||
@ -286,7 +285,7 @@ class JoinedSubclassPersister extends StandardEntityPersister
|
||||
$columnList = '';
|
||||
foreach ($this->_class->fieldMappings as $fieldName => $mapping) {
|
||||
$tableAlias = isset($mapping['inherited']) ?
|
||||
$tableAliases[$mapping['inherited']] : $baseTableAlias;
|
||||
$tableAliases[$mapping['inherited']] : $baseTableAlias;
|
||||
if ($columnList != '') $columnList .= ', ';
|
||||
$columnList .= $tableAlias . '.' . $this->_class->getQuotedColumnName($fieldName, $this->_platform);
|
||||
}
|
||||
@ -329,7 +328,15 @@ class JoinedSubclassPersister extends StandardEntityPersister
|
||||
$conditionSql = '';
|
||||
foreach ($criteria as $field => $value) {
|
||||
if ($conditionSql != '') $conditionSql .= ' AND ';
|
||||
$conditionSql .= $baseTableAlias . '.' . $this->_class->columnNames[$field] . ' = ?';
|
||||
$conditionSql .= $baseTableAlias . '.';
|
||||
if (isset($this->_class->columnNames[$field])) {
|
||||
$conditionSql .= $this->_class->getQuotedColumnName($field, $this->_platform);
|
||||
} else if ($assoc !== null) {
|
||||
$conditionSql .= $assoc->getQuotedJoinColumnName($field, $this->_platform);
|
||||
} else {
|
||||
throw DoctrineException::unrecognizedField($field);
|
||||
}
|
||||
$conditionSql .= ' = ?';
|
||||
}
|
||||
|
||||
return $sql . ($conditionSql != '' ? ' WHERE ' . $conditionSql : '');
|
||||
|
@ -452,12 +452,13 @@ class StandardEntityPersister
|
||||
* @param array $criteria The criteria by which to select the entities.
|
||||
* @param PersistentCollection The collection to fill.
|
||||
*/
|
||||
public function loadOneToManyCollection(array $criteria, PersistentCollection $collection)
|
||||
public function loadOneToManyCollection(array $criteria, PersistentCollection $coll)
|
||||
{
|
||||
$stmt = $this->_conn->prepare($this->_getSelectEntitiesSql($criteria));
|
||||
$owningAssoc = $this->_class->associationMappings[$coll->getMapping()->mappedByFieldName];
|
||||
$stmt = $this->_conn->prepare($this->_getSelectEntitiesSql($criteria, $owningAssoc));
|
||||
$stmt->execute(array_values($criteria));
|
||||
while ($result = $stmt->fetch(Connection::FETCH_ASSOC)) {
|
||||
$collection->hydrateAdd($this->_createEntity($result));
|
||||
$coll->hydrateAdd($this->_createEntity($result));
|
||||
}
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
@ -565,7 +566,7 @@ class StandardEntityPersister
|
||||
* @param array $criteria
|
||||
* @return string The SQL.
|
||||
*/
|
||||
protected function _getSelectEntitiesSql(array &$criteria)
|
||||
protected function _getSelectEntitiesSql(array &$criteria, $assoc = null)
|
||||
{
|
||||
$columnList = '';
|
||||
foreach ($this->_class->fieldNames as $field) {
|
||||
@ -593,13 +594,13 @@ class StandardEntityPersister
|
||||
}
|
||||
|
||||
if (isset($this->_class->columnNames[$field])) {
|
||||
$columnName = $this->_class->getQuotedColumnName($field, $this->_platform);
|
||||
} else if (in_array($field, $joinColumnNames)) {
|
||||
$columnName = $field;
|
||||
$conditionSql .= $this->_class->getQuotedColumnName($field, $this->_platform);
|
||||
} else if ($assoc !== null) {
|
||||
$conditionSql .= $assoc->getQuotedJoinColumnName($field, $this->_platform);
|
||||
} else {
|
||||
throw DoctrineException::unrecognizedField($field);
|
||||
}
|
||||
$conditionSql .= $columnName . ' = ?';
|
||||
$conditionSql .= ' = ?';
|
||||
}
|
||||
|
||||
return 'SELECT ' . $columnList
|
||||
|
17
tests/Doctrine/Tests/Models/Company/CompanyAuction.php
Normal file
17
tests/Doctrine/Tests/Models/Company/CompanyAuction.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\Company;
|
||||
|
||||
/** @Entity @Table(name="company_auctions") */
|
||||
class CompanyAuction extends CompanyEvent {
|
||||
/** @Column(type="string") */
|
||||
private $data;
|
||||
|
||||
public function setData($data) {
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function getData() {
|
||||
return $this->data;
|
||||
}
|
||||
}
|
35
tests/Doctrine/Tests/Models/Company/CompanyEvent.php
Normal file
35
tests/Doctrine/Tests/Models/Company/CompanyEvent.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\Company;
|
||||
|
||||
/**
|
||||
* @Entity @Table(name="company_events")
|
||||
* @InheritanceType("JOINED")
|
||||
* @DiscriminatorColumn(name="event_type", type="string")
|
||||
* @DiscriminatorMap({"auction" = "CompanyAuction", "raffle" = "CompanyRaffle"})
|
||||
*/
|
||||
class CompanyEvent {
|
||||
/**
|
||||
* @Id @Column(type="integer")
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @OneToOne(targetEntity="CompanyOrganization",cascade={"persist"})
|
||||
* @JoinColumn(name="org_id", referencedColumnName="id")
|
||||
*/
|
||||
private $organization;
|
||||
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getOrganization() {
|
||||
return $this->organization;
|
||||
}
|
||||
|
||||
public function setOrganization(CompanyOrganization $org) {
|
||||
$this->organization = $org;
|
||||
}
|
||||
}
|
30
tests/Doctrine/Tests/Models/Company/CompanyOrganization.php
Normal file
30
tests/Doctrine/Tests/Models/Company/CompanyOrganization.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\Company;
|
||||
|
||||
/** @Entity @Table(name="company_organizations") */
|
||||
class CompanyOrganization {
|
||||
/**
|
||||
* @Id @Column(type="integer")
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="CompanyEvent", mappedBy="organization", cascade={"persist"})
|
||||
*/
|
||||
private $events;
|
||||
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getEvents() {
|
||||
return $this->events;
|
||||
}
|
||||
|
||||
public function addEvent(CompanyEvent $event) {
|
||||
$this->events[] = $event;
|
||||
$event->setOrganization($this);
|
||||
}
|
||||
}
|
17
tests/Doctrine/Tests/Models/Company/CompanyRaffle.php
Normal file
17
tests/Doctrine/Tests/Models/Company/CompanyRaffle.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\Company;
|
||||
|
||||
/** @Entity @Table(name="company_raffles") */
|
||||
class CompanyRaffle extends CompanyEvent {
|
||||
/** @Column(type="string") */
|
||||
private $data;
|
||||
|
||||
public function setData($data) {
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function getData() {
|
||||
return $this->data;
|
||||
}
|
||||
}
|
@ -4,9 +4,13 @@ namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
use Doctrine\Tests\Models\Company\CompanyPerson;
|
||||
use Doctrine\Tests\Models\Company\CompanyEmployee;
|
||||
use Doctrine\Tests\Models\Company\CompanyManager;
|
||||
use Doctrine\Tests\Models\Company\CompanyPerson,
|
||||
Doctrine\Tests\Models\Company\CompanyEmployee,
|
||||
Doctrine\Tests\Models\Company\CompanyManager,
|
||||
Doctrine\Tests\Models\Company\CompanyOrganization,
|
||||
Doctrine\Tests\Models\Company\CompanyEvent,
|
||||
Doctrine\Tests\Models\Company\CompanyAuction,
|
||||
Doctrine\Tests\Models\Company\CompanyRaffle;
|
||||
|
||||
/**
|
||||
* Functional tests for the Class Table Inheritance mapping strategy.
|
||||
@ -176,4 +180,46 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$friends = $result[0]->getFriends();
|
||||
$this->assertEquals('Jonathan', $friends[0]->getName());
|
||||
}
|
||||
|
||||
public function testLazyLoading1()
|
||||
{
|
||||
$org = new CompanyOrganization;
|
||||
$event1 = new CompanyAuction;
|
||||
$event1->setData('auction');
|
||||
$org->addEvent($event1);
|
||||
$event2 = new CompanyRaffle;
|
||||
$event2->setData('raffle');
|
||||
$org->addEvent($event2);
|
||||
|
||||
$this->_em->persist($org);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$orgId = $org->getId();
|
||||
|
||||
$this->_em->getConfiguration()->setAllowPartialObjects(false);
|
||||
|
||||
$q = $this->_em->createQuery('select a from Doctrine\Tests\Models\Company\CompanyOrganization a where a.id = ?1');
|
||||
$q->setParameter(1, $orgId);
|
||||
|
||||
$result = $q->getResult();
|
||||
|
||||
$this->assertEquals(1, count($result));
|
||||
$this->assertTrue($result[0] instanceof CompanyOrganization);
|
||||
|
||||
$events = $result[0]->getEvents();
|
||||
|
||||
$this->assertTrue($events instanceof \Doctrine\ORM\PersistentCollection);
|
||||
$this->assertFalse($events->isInitialized());
|
||||
|
||||
$this->assertEquals(2, count($events));
|
||||
if ($events[0] instanceof CompanyAuction) {
|
||||
$this->assertTrue($events[1] instanceof CompanyRaffle);
|
||||
} else {
|
||||
$this->assertTrue($events[0] instanceof CompanyRaffle);
|
||||
$this->assertTrue($events[1] instanceof CompanyAuction);
|
||||
}
|
||||
|
||||
$this->_em->getConfiguration()->setAllowPartialObjects(true);
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,11 @@ class OrmFunctionalTestCase extends OrmTestCase
|
||||
'company' => array(
|
||||
'Doctrine\Tests\Models\Company\CompanyPerson',
|
||||
'Doctrine\Tests\Models\Company\CompanyEmployee',
|
||||
'Doctrine\Tests\Models\Company\CompanyManager'
|
||||
'Doctrine\Tests\Models\Company\CompanyManager',
|
||||
'Doctrine\Tests\Models\Company\CompanyOrganization',
|
||||
'Doctrine\Tests\Models\Company\CompanyEvent',
|
||||
'Doctrine\Tests\Models\Company\CompanyAuction',
|
||||
'Doctrine\Tests\Models\Company\CompanyRaffle'
|
||||
),
|
||||
'ecommerce' => array(
|
||||
'Doctrine\Tests\Models\ECommerce\ECommerceCart',
|
||||
@ -94,6 +98,10 @@ class OrmFunctionalTestCase extends OrmTestCase
|
||||
$conn->executeUpdate('DELETE FROM company_employees');
|
||||
$conn->executeUpdate('UPDATE company_persons SET spouse_id = NULL');
|
||||
$conn->executeUpdate('DELETE FROM company_persons');
|
||||
$conn->executeUpdate('DELETE FROM company_raffles');
|
||||
$conn->executeUpdate('DELETE FROM company_auctions');
|
||||
$conn->executeUpdate('DELETE FROM company_events');
|
||||
$conn->executeUpdate('DELETE FROM company_organizations');
|
||||
}
|
||||
if (isset($this->_usedModelSets['generic'])) {
|
||||
$conn->executeUpdate('DELETE FROM date_time_model');
|
||||
|
Loading…
x
Reference in New Issue
Block a user