【发布时间】:2017-05-06 05:56:09
【问题描述】:
我想在组和用户之间使用 Symfony 2 在 Doctrine 中建立多对多关系:许多用户可以在多个组中,并且许多组可以有多个用户。
然后在我的实体中,我这样做:
Groupe.php
/**
* Many Groups have Many clients.
* @ORM\ManyToMany(targetEntity="Utilisateurs\UtilisateursBundle\Entity\Client", mappedBy="groupe")
* @ORM\JoinTable(name="client_groupe")
*/
private $clients;
/**
* Get clients
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getClients()
{
return $this->clients;
}
Client.php
/**
* @ORM\ManyToMany(targetEntity="Ecommerce\EcommerceBundle\Entity\Groupe", inversedBy="clients")
* @ORM\JoinTable(name="client_groupe",
* joinColumns={@ORM\JoinColumn(name="client_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="groupe_id", referencedColumnName="id")}
* )
*/
private $groupe;
但是当我在我的实体$groupe 上调用getClients() 函数时,出现以下错误:
FROM client t0 WHERE client_groupe.groupe_id = ?' with params ["2"]:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'client_groupe.groupe_id' in 'where clause'
它不会在 from 子句中添加 client_groupe 表。
有人可以帮助我吗?
【问题讨论】:
-
尝试删除文件client.php中的
name="group_id"和name="client_id",这样symfony可以自己生成列。