Skip to content

Commit

Permalink
Add a find version to allow to override it in future for performance …
Browse files Browse the repository at this point in the history
…optimizations
  • Loading branch information
bakura10 committed Jul 23, 2012
1 parent f1ac389 commit 1cda09d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/DoctrineORMModule/Hydrator/DoctrineEntity.php
Expand Up @@ -105,11 +105,11 @@ public function hydrate(array $data, $object)
protected function toOne($valueOrObject, $target)
{
if (is_numeric($valueOrObject)) {
return $this->objectManager->find($target, $valueOrObject);
return $this->find($target, $valueOrObject);
}

$identifiers = $this->metadata->getIdentifierValues($valueOrObject);
return $this->objectManager->find($target, $identifiers);
return $this->find($target, $identifiers);
}

/**
Expand All @@ -126,14 +126,24 @@ protected function toMany($valueOrObject, $target)
$values = array();
foreach($valueOrObject as $value) {
if (is_numeric($value)) {
$values[] = $this->objectManager->find($target, $value);
$values[] = $this->find($target, $value);
continue;
}

$identifiers = $this->metadata->getIdentifierValues($valueOrObject);
$values[] = $this->objectManager->find($target, $identifiers);
$values[] = $this->find($target, $identifiers);
}

return $values;
}

/**
* @param string $target
* @param int|array $identifiers
* @return object
*/
protected function find($target, $identifiers)
{
return $this->objectManager->find($target, $identifiers);
}
}

0 comments on commit 1cda09d

Please sign in to comment.