I'm using Doctrine 2.4 on a symfony 6. I've always used findOneBy without a problem but I'm working on a new project now and for some reason this stopped working and can't understand why.
This does not work as I'm getting null.
$test = $this->em->getRepository(MyEntity::class)->findOneBy(['id' => $id]);
but
$qb = $this->em->createQueryBuilder();
$test2 = $qb->select('t')
->from(MyEntity::class, 't')
->where('t.id = :id')
->setParameter('id', $id)
->getQuery()->getSingleResult();
This totally works.
I'm trying to understand why the first method is not giving me any results when the value $id is the same and they both use EntityManagerInterface in the constructor.
As i mentioned, I've been using findOneBy for quite some time and never had a problem.
Nevermind, i was focusing so much on the usage that didn't pay attention to my Repository inside the Entity.