1
0
Fork 0
mirror of synced 2025-04-01 12:26:11 +03:00

Fix wrong logic

This commit is contained in:
Michaël Gallego 2013-12-22 17:00:56 +01:00
parent 738cc250f8
commit 9385a600cf
2 changed files with 16 additions and 7 deletions

View file

@ -876,7 +876,7 @@ final class PersistentCollection implements Collection, Selectable
if ($this->association['type'] === ClassMetadata::MANY_TO_MANY) {
$persister = $this->em->getUnitOfWork()->getCollectionPersister($this->association);
return new ArrayCollection($persister->loadCriteria($this, $this->owner, $criteria));
return new ArrayCollection($persister->loadCriteria($this, $criteria));
}
$builder = Criteria::expr();

View file

@ -556,29 +556,38 @@ class ManyToManyPersister extends AbstractCollectionPersister
* Loads Entities matching the given Criteria object.
*
* @param PersistentCollection $coll
* @param object $owner
* @param \Doctrine\Common\Collections\Criteria $criteria
* @return array
*/
public function loadCriteria(PersistentCollection $coll, $owner, Criteria $criteria)
public function loadCriteria(PersistentCollection $coll, Criteria $criteria)
{
list($quotedJoinTable, $whereClauses, $params) = $this->getJoinTableRestrictions($coll, $owner, true);
$mapping = $coll->getMapping();
$owner = $coll->getOwner();
$ownerMetadata = $this->em->getClassMetadata(get_class($owner));
$whereClauses = $params = array();
foreach ($mapping['relationToSourceKeyColumns'] as $key => $value) {
$whereClauses[] = sprintf('t.%s = ?', $key);
$params[] = $ownerMetadata->getFieldValue($owner, $value);
}
$parameters = $this->expandCriteriaParameters($criteria);
foreach ($parameters as $parameter) {
list($name, $value) = $parameter;
$whereClauses[] = sprintf("te.%s = ?", $name);
$params[] = $value;
$whereClauses[] = sprintf("te.%s = ?", $name);
$params[] = $value;
}
$mapping = $coll->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);
$sql = 'SELECT * FROM ' . $tableName . ' te'
. ' JOIN ' . $quotedJoinTable . ' ON'
. ' JOIN ' . $joinTable . ' t ON'
. implode(' AND ', $onConditions)
. ' WHERE ' . implode(' AND ', $whereClauses);