[英]Doctrine and Symfony2 ManyToMany: Association refers to inverse side that doesn't exist error
Im trying to establish a many to many relationship between two Entities All I need is the exact same code that is documented here: http://docs.doctrine-project.org/en/latest/reference/association-mapping.html#many-to-many-bidirectional 我试图在两个实体之间建立多对多关系。我所需要的是这里记录的完全相同的代码: http : //docs.doctrine-project.org/en/latest/reference/association-mapping.html#many对多双向
here is the example code in case you don't want to open the link 这是示例代码,以防您不想打开链接
<?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();
}
// ...
}
Here is my code: 这是我的代码:
//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();
}
}
It triggers this error: 它触发此错误:
The association Gabriel\\UploadBundle\\Entity\\Image#imageowner refers to the inverse side field Gabriel\\UserBundle\\Entity\\User#ownedimage which does not exist.
关联Gabriel \\ UploadBundle \\ Entity \\ Image#imageowner指的是不存在的反向字段Gabriel \\ UserBundle \\ Entity \\ User#ownedimage。
I have been searching for hours I would appreciate if someone had an idea 我一直在寻找几个小时,如果有人有一个主意,我将不胜感激
Why a ManyToMany relationship. 为什么要建立一对多关系。 For me it's a OneToMany relationship.
对我来说,这是一个一对多的关系。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.