Skip to content

Commit

Permalink
Fix LargeCollection to work with recent association changes
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Aug 10, 2010
1 parent 0582290 commit a1657f0
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/DoctrineExtensions/LargeCollections/LargeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public function count(Collection $collection)
$em = $this->getEntityManager($collection);

$assoc = $collection->getMapping();
$sourceMetadata = $em->getClassMetadata($assoc->sourceEntityName);
$targetMetadata = $em->getClassMetadata($assoc->targetEntityName);
$sourceMetadata = $em->getClassMetadata($assoc['sourceEntity']);
$targetMetadata = $em->getClassMetadata($assoc['targetEntity']);

if (!count($targetMetadata->identifier) == 1) {
throw new \UnexpectedValueException("Only Relations with Entities using Single Primary Keys are supported.");
}

$dql = 'SELECT COUNT(r.' . $targetMetadata->identifier[0] . ') AS collectionCount '.
'FROM ' . $sourceMetadata->name . ' o LEFT JOIN o.' . $assoc->sourceFieldName . ' r ' .
'FROM ' . $sourceMetadata->name . ' o LEFT JOIN o.' . $assoc['fieldName'] . ' r ' .
'WHERE ' . $this->getWhereConditions($sourceMetadata);
$query = $em->createQuery($dql);

Expand Down Expand Up @@ -99,17 +99,17 @@ public function getSliceQuery(PersistentCollection $collection, $limit, $offset
$em = $this->getEntityManager($collection);

$assoc = $collection->getMapping();
$sourceMetadata = $em->getClassMetadata($assoc->sourceEntityName);
$targetMetadata = $em->getClassMetadata($assoc->targetEntityName);
$sourceMetadata = $em->getClassMetadata($assoc['sourceEntity']);
$targetMetadata = $em->getClassMetadata($assoc['targetEntity']);

if ($assoc->isOwningSide && !$assoc->inversedBy) {
if ($assoc['isOwningSide'] && !$assoc['inversedBy']) {
throw new \UnexpectedValueException("Only bi-directional collections can be sliced.");
}

if ($assoc->isOwningSide) {
$assocField = $assoc->inversedBy;
if ($assoc['isOwningSide']) {
$assocField = $assoc['inversedBy'];
} else {
$assocField = $assoc->mappedBy;
$assocField = $assoc['mappedBy'];
}

$dql = 'SELECT r FROM ' . $targetMetadata->name . ' r JOIN r.' . $assocField . ' o '.
Expand Down

0 comments on commit a1657f0

Please sign in to comment.