我有两个 netities 用户和服务以及由学说生成的连接表 user_service,我尝试在此处添加多对多关系,这是我添加的注释:
实体用户端:
/**
* @ORM\ManyToMany(targetEntity="Service", inversedBy="users")
* @ORM\JoinTable(name="user_service",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="service_id", referencedColumnName="id")}
* )
*/
protected $services;
实体服务端:
/**
* @ORM\ManyToMany(targetEntity="User", mappedBy="services")
*/
protected $users;
一切似乎都很好,但是当我提出这个要求时:
$query = $em->createQuery(
'SELECT u
FROM ApplicationFrontBundle:User u
JOIN u.service s
WHERE u.id = :id
'
)->setParameters(array('id'=> $id));
$services = $query->getArrayResult();
我有这个错误:
[Semantical Error] line 0, col 91 near 's
': Error: Class Application\FrontBundle\Entity\User has no association named service
但是当我通过它工作的对象来做这件事时,问题是它执行了很多请求