1
0
mirror of synced 2025-03-21 23:43:53 +03:00

#1178 - correcting filtering when initializing a one-to-many collection that has composite complex (custom DBAL types) identifiers

This commit is contained in:
Marco Pivetta 2015-01-17 05:55:16 +01:00
parent 096bd90aed
commit ce446a6f03
2 changed files with 35 additions and 10 deletions

View File

@ -67,7 +67,17 @@ class OneToManyPersister extends AbstractCollectionPersister
$persister = $this->uow->getEntityPersister($mapping['targetEntity']); $persister = $this->uow->getEntityPersister($mapping['targetEntity']);
return $persister->load(array($mapping['mappedBy'] => $collection->getOwner(), $mapping['indexBy'] => $index), null, $mapping, array(), null, 1); return $persister->load(
array(
$mapping['mappedBy'] => $collection->getOwner(),
$mapping['indexBy'] => $index
),
null,
$mapping,
array(),
null,
1
);
} }
/** /**

View File

@ -864,7 +864,7 @@ class BasicEntityPersister implements EntityPersister
list($params, $types) = $valueVisitor->getParamsAndTypes(); list($params, $types) = $valueVisitor->getParamsAndTypes();
foreach ($params as $param) { foreach ($params as $param) {
$sqlParams[] = $this->getValue($param); $sqlParams[] = PersisterHelper::getValue($param, $this->em);
} }
foreach ($types as $type) { foreach ($types as $type) {
@ -1717,7 +1717,8 @@ class BasicEntityPersister implements EntityPersister
*/ */
private function getOneToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null) private function getOneToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null)
{ {
$criteria = array(); $criteria = array();
$parameters = array();
$owningAssoc = $this->class->associationMappings[$assoc['mappedBy']]; $owningAssoc = $this->class->associationMappings[$assoc['mappedBy']];
$sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']); $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']);
@ -1734,15 +1735,29 @@ class BasicEntityPersister implements EntityPersister
} }
$criteria[$tableAlias . "." . $targetKeyColumn] = $value; $criteria[$tableAlias . "." . $targetKeyColumn] = $value;
$parameters[] = array(
'value' => $value,
'field' => $field,
'class' => $sourceClass,
);
continue; continue;
} }
$criteria[$tableAlias . "." . $targetKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity); $field = $sourceClass->fieldNames[$sourceKeyColumn];
$value = $sourceClass->reflFields[$field]->getValue($sourceEntity);
$criteria[$tableAlias . "." . $targetKeyColumn] = $value;
$parameters[] = array(
'value' => $value,
'field' => $field,
'class' => $sourceClass,
);
} }
$sql = $this->getSelectSQL($criteria, $assoc, null, $limit, $offset); $sql = $this->getSelectSQL($criteria, $assoc, null, $limit, $offset);
list($params, $types) = $this->expandParameters($criteria); list($params, $types) = $this->expandToManyParameters($parameters);
return $this->conn->executeQuery($sql, $params, $types); return $this->conn->executeQuery($sql, $params, $types);
} }
@ -1874,11 +1889,11 @@ class BasicEntityPersister implements EntityPersister
. $this->getLockTablesSql(null) . $this->getLockTablesSql(null)
. ' WHERE ' . $this->getSelectConditionSQL($criteria); . ' WHERE ' . $this->getSelectConditionSQL($criteria);
list($params) = $this->expandParameters($criteria); list($params, $types) = $this->expandParameters($criteria);
if (null !== $extraConditions) { if (null !== $extraConditions) {
$sql .= ' AND ' . $this->getSelectConditionCriteriaSQL($extraConditions); $sql .= ' AND ' . $this->getSelectConditionCriteriaSQL($extraConditions);
list($criteriaParams, $values) = $this->expandCriteriaParameters($extraConditions); list($criteriaParams, $types) = $this->expandCriteriaParameters($extraConditions);
$params = array_merge($params, $criteriaParams); $params = array_merge($params, $criteriaParams);
} }
@ -1887,7 +1902,7 @@ class BasicEntityPersister implements EntityPersister
$sql .= ' AND ' . $filterSql; $sql .= ' AND ' . $filterSql;
} }
return (bool) $this->conn->fetchColumn($sql, $params); return (bool) $this->conn->fetchColumn($sql, $params, 0, $types);
} }
/** /**