'doctrine criteria memberOf

I get errors

in vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php (line 1611)
in vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.phpsprintf (line 1611)
in vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/SqlExpressionVisitor.php->getSelectConditionStatementSQL (line 58)
in vendor/doctrine/collections/lib/Doctrine/Common/Collections/Expr/ExpressionVisitor.php->walkComparison (line 47)
in vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/SqlExpressionVisitor.php->dispatch (line 73)
in vendor/doctrine/collections/lib/Doctrine/Common/Collections/Expr/ExpressionVisitor.php->walkCompositeExpression (line 53)
in vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php->dispatch (line 1570)
in vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php->getSelectConditionCriteriaSQL (line 296)
in vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php->getSelectSQL (line 833)
in vendor/doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php->loadCriteria (line 657)
in /Model/AlertRelationTrait.php->matching (line 42)

query build

 $criteria = Criteria::create();

query 

 $criteria->where(Criteria::expr()->memberOf('createdFor',$myUser));

  return $this->alerts->matching($criteria);

mapping

   /**
     * @ORM\ManyToMany(targetEntity="AppBundle\Entity\User",cascade={"persist"})
     * @var User|ArrayCollection
     */
    protected $createdFor;


Solution 1:[1]

Need to define owning and inverse side of many to many relation (https://www.doctrine-project.org/projects/doctrine-orm/en/2.9/reference/association-mapping.html#owning-and-inverse-side-on-a-manytomany-association)

    /**
     * @ORM\ManyToMany(targetEntity="AppBundle\Entity\User",mappedBy="alerts")
     * @var ArrayCollection
     */
    protected $createdFor;

And then on the other side

    /**
     * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Alert",inversedBy="createdFor")
     * @var ArrayCollection
     */
    protected $alerts;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tez