学说标准成员

doctrine criteria memberOf

我遇到错误

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)

查询构建

 $criteria = Criteria::create();

query 

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

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

映射

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

需要定义多对多关系的拥有和反面(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;

然后在另一边

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