【发布时间】:2014-01-31 11:07:03
【问题描述】:
我试图在两个实体之间建立多对多关系 我所需要的只是此处记录的完全相同的代码: http://docs.doctrine-project.org/en/latest/reference/association-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 \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 其中 不存在。
我一直在寻找几个小时,如果有人有想法,我将不胜感激
【问题讨论】:
-
我猜你试图清除缓存?您的捆绑包是否都在 AppKernel.php 中定义?在 config.yml 中?
-
是的,是的,是的,你也不能清除缓存,因为控制台会触发错误。
-
所以您手动删除了
app/cache中的dev文件夹? -
触发app_dev.php时缓存不会自动重建吗?
-
现在也试过了,同样的,但我找到了另一种解决问题的方法,所以没关系
标签: php symfony doctrine-orm doctrine