Feature Request
What
The EntityManager::getReference() should not return null when the found Entity does not match the given $entityName.
Why
We are using the power of getReference() to reduce the load on our application because we do the sanity checks ourselves and this way can easily associate relations to entities.
But because of the (possibly very wrong) situation of this mismatch the method returns null instead of throwing an Exception. And because of this, everywhere we use this we need to first check the output of the getReference() which kinda defeats the purpose in our opinion.
How
In the EntityManagerInterface remove the nullability of the the method getReference() and in the implementation EntityManager change the output of the if statement:
// Check identity map first, if its already in there just return it.
if ($entity !== false) {
return $entity instanceof $class->name ? $entity : null;
}
to e.g.:
// Check identity map first, if its already in there just return it.
if ($entity !== false) {
if (!$entity instanceof $class->name) {
// Non-existing Exception, but something like this
throw MismatchingEntity::create($class->name);
}
return $entity;
}
Feature Request
What
The
EntityManager::getReference()should not returnnullwhen the found Entity does not match the given$entityName.Why
We are using the power of
getReference()to reduce the load on our application because we do the sanity checks ourselves and this way can easily associate relations to entities.But because of the (possibly very wrong) situation of this mismatch the method returns
nullinstead of throwing an Exception. And because of this, everywhere we use this we need to first check the output of thegetReference()which kinda defeats the purpose in our opinion.How
In the
EntityManagerInterfaceremove the nullability of the the methodgetReference()and in the implementationEntityManagerchange the output of the if statement:to e.g.: