我与两个实体有@ManyToMany关系。
我有(短代码)
class Photo
{
/**
* @ORM\ManyToMany(targetEntity="Application\Sonata\UserBundle\Entity\User", mappedBy="photos")
*/
protected $users;
}
class User
{
/**
* @ORM\ManyToMany(targetEntity="MyBundle\PhotoBundle\Entity\Photo", inversedBy="users", cascade={"persist"})
* @ORM\JoinTable(name="user_photos")
*/
protected $photos;
}
php app/console doctrine:schema:validate
-> [Mapping] FAIL - The entity-class 'MyBundle\PhotoBundle\Entity\Photo' mapping is invalid:
* The association MyBundle\PhotoBundle\Entity\Photo#users refers to the owning side field Application\Sonata\UserBundle\Entity\User#photos which does not exist.
我看着堆栈,我尝试了一些事情,但我仍然有问题。
答案 0 :(得分:0)
试试这个
class Photo
{
/**
* @ORM\ManyToMany(targetEntity="Application\Sonata\UserBundle\Entity\User", mappedBy="photo")
*/
protected $users;
}
class User
{
/**
* @ORM\ManyToMany(targetEntity="MyBundle\PhotoBundle\Entity\Photo", inversedBy="users", cascade={"persist"})
* @ORM\JoinTable(name="user_photos")
*/
protected $photos;
}