[英]Doctrine and Symfony2 : Association refers to inverse side that doesn't exist error
[英]Doctrine and Symfony2 ManyToMany: Association refers to inverse side that doesn't exist error
我试图在两个实体之间建立多对多关系。我所需要的是这里记录的完全相同的代码: http : //docs.doctrine-project.org/en/latest/reference/association-mapping.html#many对多双向
这是示例代码,以防您不想打开链接
<?php
/** @Entity **/
class User
{
// ...
/**
* @ManyToMany(targetEntity="Group", inversedBy="users")
* @JoinTable(name="users_groups")
**/
private $groups;
public function __construct() {
$this->groups = new \Doctrine\Common\Collections\ArrayCollection();
}
// ...
}
/** @Entity **/
class Group
{
// ...
/**
* @ManyToMany(targetEntity="User", mappedBy="groups")
**/
private $users;
public function __construct() {
$this->users = new \Doctrine\Common\Collections\ArrayCollection();
}
// ...
}
这是我的代码:
//My User entity
namespace Gabriel\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
class User extends BaseUser
{
//...
/**
* @ORM\ManyToMany(targetEntity="Gabriel\UploadBundle\Entity\Image", mappedBy="imageowner")
*/
protected $ownedimage;
public function __construct()
{
$this->ownedimage = new \Doctrine\Common\Collections\ArrayCollection();
}
//...
}
//My Image entity
namespace Gabriel\UploadBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
class Image
{
/**
* @ORM\ManyToMany(targetEntity="Gabriel\UserBundle\Entity\User", inversedBy="ownedimage")
* @ORM\JoinTable(name="imageowner_ownedimage")
*/
protected $imageowner;
public function __construct()
{
$this->imageowner = new \Doctrine\Common\Collections\ArrayCollection();
}
}
它触发此错误:
关联Gabriel \\ UploadBundle \\ Entity \\ Image#imageowner指的是不存在的反向字段Gabriel \\ UserBundle \\ Entity \\ User#ownedimage。
我一直在寻找几个小时,如果有人有一个主意,我将不胜感激
为什么要建立一对多关系。 对我来说,这是一个一对多的关系。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.