Symfony2和DQL:查询ManyToMany关系

时间:2015-02-28 16:40:03

标签: mysql symfony doctrine-orm dql

我有两个实体:用户和存档,它们之间有很多关系: 在用户实体中,我有:

/**
 * represent the script collection for a user
 * @ORM\ManyToMany(targetEntity="My\ApplicationBundle\Entity\Archive", inversedBy="users")
 * @ORM\JoinTable(name="collection")
 **/
private $collection;

并存档:

/**
 * represent the users having this archive in their collection
 * @ORM\ManyToMany(targetEntity="My\UserBundle\Entity\User", mappedBy="collection")
 **/
private $users;

此关系生成一个名为“collection”的表,其中包含user_id和archive_id字段。在这些表中插入数据不是问题。

现在,我想获得特定用户的所有存档,但我不知道从哪里开始。我试过了

$this->getUser->getCollection()

但它似乎没有按预期工作。可能我需要一些自定义存储库类?非常感谢

0 个答案:

没有答案