I expected that Doctrine 2 repository would check the EntityManager
for results first. But it doesn't.
This code represents the issue.
$em = $this->getEntityManager();
$firstName = 'Michael';
$lastName = 'Jordan';
$userEntity = new User($firstName, $lastName);
$em->persist($userEntity);
$userRepository = $em->getRepository('UserRepository');
$expectingMichaelJordanUserEntity = $userRepository->findOneBy(array('firstName' => $firstName, 'lastName' => $lastName));
In this example the $expectingMichaelJordanUserEntity
is null
because the entity has not been saved to the database. Shouldn't it look inside the entity manager for persisted entities first?
Is that the meaning or is there a way to get my example to return the persisted User
entity?