Merge branch 'DDC-3719-fix' of github.com:jeanCarloMachado/doctrine2 into many-to-many-criteria-fixes
This commit is contained in:
commit
f0accca99d
@ -236,29 +236,41 @@ class ManyToManyPersister extends AbstractCollectionPersister
|
||||
$mapping = $collection->getMapping();
|
||||
$owner = $collection->getOwner();
|
||||
$ownerMetadata = $this->em->getClassMetadata(get_class($owner));
|
||||
$id = $this->uow->getEntityIdentifier($owner);
|
||||
$targetClass = $this->em->getClassMetadata($mapping['targetEntity']);
|
||||
$onConditions = $this->getOnConditionSQL($mapping);
|
||||
$whereClauses = $params = array();
|
||||
|
||||
foreach ($mapping['relationToSourceKeyColumns'] as $key => $value) {
|
||||
if ( ! $mapping['isOwningSide']) {
|
||||
$associationSourceClass = $targetClass;
|
||||
$mapping = $targetClass->associationMappings[$mapping['mappedBy']];
|
||||
$sourceRelationMode = 'relationToTargetKeyColumns';
|
||||
} else {
|
||||
$associationSourceClass = $ownerMetadata;
|
||||
$sourceRelationMode = 'relationToSourceKeyColumns';
|
||||
}
|
||||
|
||||
foreach ($mapping[$sourceRelationMode] as $key => $value) {
|
||||
$whereClauses[] = sprintf('t.%s = ?', $key);
|
||||
$params[] = $ownerMetadata->getFieldValue($owner, $value);
|
||||
$params[] = $ownerMetadata->containsForeignIdentifier
|
||||
? $id[$ownerMetadata->getFieldForColumn($value)]
|
||||
: $id[$ownerMetadata->fieldNames[$value]];
|
||||
}
|
||||
|
||||
$parameters = $this->expandCriteriaParameters($criteria);
|
||||
|
||||
foreach ($parameters as $parameter) {
|
||||
list($name, $value) = $parameter;
|
||||
$whereClauses[] = sprintf('te.%s = ?', $name);
|
||||
$field = $this->quoteStrategy->getColumnName($name, $targetClass, $this->platform);
|
||||
$whereClauses[] = sprintf('te.%s = ?', $field);
|
||||
$params[] = $value;
|
||||
}
|
||||
|
||||
$mapping = $collection->getMapping();
|
||||
$targetClass = $this->em->getClassMetadata($mapping['targetEntity']);
|
||||
$tableName = $this->quoteStrategy->getTableName($targetClass, $this->platform);
|
||||
$joinTable = $this->quoteStrategy->getJoinTableName($mapping, $ownerMetadata, $this->platform);
|
||||
$onConditions = $this->getOnConditionSQL($mapping);
|
||||
$joinTable = $this->quoteStrategy->getJoinTableName($mapping, $associationSourceClass, $this->platform);
|
||||
|
||||
$rsm = new Query\ResultSetMappingBuilder($this->em);
|
||||
$rsm->addRootEntityFromClassMetadata($mapping['targetEntity'], 'te');
|
||||
$rsm->addRootEntityFromClassMetadata($targetClass->name, 'te');
|
||||
|
||||
$sql = 'SELECT ' . $rsm->generateSelectClause()
|
||||
. ' FROM ' . $tableName . ' te'
|
||||
|
54
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3719Test.php
Normal file
54
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3719Test.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\Tests\Models\Company\CompanyFlexContract;
|
||||
use Doctrine\Tests\Models\Company\CompanyManager;
|
||||
|
||||
/**
|
||||
* @author Jean Carlo Machado <contato@jeancarlomachado.com.br>
|
||||
*/
|
||||
class DDC3719Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->useModelSet('company');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-3719
|
||||
*/
|
||||
public function testCriteriaOnNotOwningSide()
|
||||
{
|
||||
$manager = new CompanyManager();
|
||||
$manager->setName('Gandalf');
|
||||
$manager->setSalary(666);
|
||||
$manager->setTitle('Boss');
|
||||
$manager->setDepartment('Marketing');
|
||||
$this->_em->persist($manager);
|
||||
|
||||
$contractA = new CompanyFlexContract();
|
||||
$contractA->markCompleted();
|
||||
$contractA->addManager($manager);
|
||||
$this->_em->persist($contractA);
|
||||
|
||||
$contractB = new CompanyFlexContract();
|
||||
$contractB->addManager($manager);
|
||||
$this->_em->persist($contractB);
|
||||
|
||||
$this->_em->flush();
|
||||
$this->_em->refresh($manager);
|
||||
|
||||
$contracts = $manager->managedContracts;
|
||||
static::assertCount(2, $contracts);
|
||||
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where(Criteria::expr()->eq("completed", true));
|
||||
|
||||
$completedContracts = $contracts->matching($criteria);
|
||||
static::assertCount(1, $completedContracts);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user