diff --git a/ParamConverter/EntityParamConverter.php b/ParamConverter/EntityParamConverter.php index f9545df..3d5aed1 100644 --- a/ParamConverter/EntityParamConverter.php +++ b/ParamConverter/EntityParamConverter.php @@ -43,11 +43,19 @@ public function __construct(EntityBuilder $builder, EntityManager $entityManager */ function apply(Request $request, ParamConverter $configuration) { - $id = $this->requestFinder->find('id', $request); $class = $configuration->getClass(); + $identifiers = $this->entityManager->getClassMetadata($class)->getIdentifierFieldNames(); - if ($id) { - $entity = $this->entityManager->getRepository($configuration->getClass())->find($id); + $search = []; + foreach ($identifiers as $identifier) { + $value = $this->requestFinder->find($identifier, $request); + if ($value !== null) { + $search[$identifier] = $value; + } + } + + if (count($search) === count($identifiers)) { + $entity = $this->entityManager->getRepository($configuration->getClass())->findBy($search); if (!$entity) { $entity = new $class(); }