Doctrine and Symfony2 ManyToMany:关联是指不存在错误的反面



我试图建立两个实体之间的许多关系我所需要的只是此处记录的完全相同的代码:http://docs.doctrine-project.org/en/latest/reference/sosociation-mapping.html#many-to-many-bidirectional

这是示例代码,以防您不想打开链接

<?php
/** @Entity **/
class User
{
    // ...
    /**
     * @ManyToMany(targetEntity="Group", inversedBy="users")
     * @JoinTable(name="users_groups")
     **/
    private $groups;
    public function __construct() {
        $this->groups = new DoctrineCommonCollectionsArrayCollection();
    }
    // ...
}
/** @Entity **/
class Group
{
    // ...
    /**
     * @ManyToMany(targetEntity="User", mappedBy="groups")
     **/
    private $users;
    public function __construct() {
        $this->users = new DoctrineCommonCollectionsArrayCollection();
    }
    // ...
}

这是我的代码:

//My User entity
namespace GabrielUserBundleEntity;
use DoctrineORMMapping as ORM;
class User extends BaseUser
{
    //...
    /**
     * @ORMManyToMany(targetEntity="GabrielUploadBundleEntityImage", mappedBy="imageowner")
     */
    protected $ownedimage;
    public function __construct()
    {
        $this->ownedimage = new DoctrineCommonCollectionsArrayCollection();
    }
    //...
}

//My Image entity
namespace GabrielUploadBundleEntity;
use DoctrineORMMapping as ORM;
class Image
{
    /**
     * @ORMManyToMany(targetEntity="GabrielUserBundleEntityUser", inversedBy="ownedimage")
     * @ORMJoinTable(name="imageowner_ownedimage")
     */
    protected $imageowner;
    public function __construct()
    {
        $this->imageowner = new DoctrineCommonCollectionsArrayCollection();
    }
}

它触发此错误:

态 逆侧字段gabriel userbundle entity user#ownedimage when 不存在。

我一直在搜索几个小时,如果有人有一个想法

,我将不胜感激

为什么要有多个关系。对我来说,这是一种on依者的关系。

相关内容

  • 没有找到相关文章

最新更新