How to find by Uuid ?
GaylordP opened this issue · comments
Hello :)
I use Symfony 5, Doctrine, MySQL 8 and Ramsey uuid-doctrine.
This is my ID Forum
entity :
`
/**
* @var \Ramsey\Uuid\UuidInterface
*
* @ORM\Id
* @ORM\Column(type="uuid_binary_ordered_time", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidOrderedTimeGenerator")
*/
private $id;
`
I have this method on my repository :
`
public function findById(string $forumId): ?Forum
{
return $this
->createQueryBuilder('forum')
->andWhere('forum.id = :forumId')
->setParameter('forumId', $forumId)
->select('
forum
')
->getQuery()
->getOneOrNullResult()
;
}
`
Now I want to retrieve this forum using the method findById()
(with paremeters url, /forums/{uuid}/).
- My string UUID is 37b3c336-4b4d-11ea-ab15-309c23145bb0
But these tests return null :
`
findById('37b3c336-4b4d-11ea-ab15-309c23145bb0');
findById(Uuid::fromString('37b3c336-4b4d-11ea-ab15-309c23145bb0'));
findById(Uuid::fromString('37b3c336-4b4d-11ea-ab15-309c23145bb0')->getBytes());
`
Thanks very much for your help
I think you can use the find method find('37b3c336-4b4d-11ea-ab15-309c23145bb0')