You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given two entities and a random class with similar name (to confuse the developer, but could be anything really):
/** @Entity */class User
{
// .../** * @ManyToMany(targetEntity="Group", inversedBy="users", cascade={"all"}) */private$groups;
publicfunction__construct() {
$this->groups = new \Doctrine\Common\Collections\ArrayCollection();
}
}
/** @Entity */class Group
{
/** * @ManyToMany(targetEntity="User", mappedBy="groups") */private$users;
publicfunction__construct() {
$this->users = new \Doctrine\Common\Collections\ArrayCollection();
}
}
class Group2
{}
If you add an instance of Group2 to User#$groups and try to persist, an exception will be thrown from Doctrine\ORM\UnitOfWork:832:
if (! ($entryinstanceof$targetClass->name)) {
throw ORMInvalidArgumentException::invalidAssociation($targetClass, $assoc, $entry);
}
However, instead of reading like:
Expected value of type "AppBundle\Entity\Group" for association field "AppBundle\Entity\User#$groups", got "AppBundle\Entity\Group2" instead.
It reads like:
Expected value of type "Doctrine\Common\Collections\Collection|array" for association field "AppBundle\Entity\User#$groups", got "AppBundle\Entity\Group2" instead.
Simply because the $expectedType isn't set correctly for many-to-many associations in Doctrine\ORM:201:
@foaly-nr1 could you please send us a failing test case that reproduces that behaviour? It would help us a lot to identify and fix the issue you're describing.
Given two entities and a random class with similar name (to confuse the developer, but could be anything really):
If you add an instance of Group2 to User#$groups and try to persist, an exception will be thrown from Doctrine\ORM\UnitOfWork:832:
However, instead of reading like:
It reads like:
Simply because the
$expectedType
isn't set correctly for many-to-many associations in Doctrine\ORM:201:The text was updated successfully, but these errors were encountered: