ManyToMany双向[语义错误]用户没有名为服务的关联

时间:2012-08-05 11:14:40

标签: symfony doctrine-orm many-to-many bidirectional

我有两个netities用户&服务和doctrine生成的连接表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

但是,当我通过它工作的对象来做它时,问题是它执行了很多请求

1 个答案:

答案 0 :(得分:0)

因为您将其命名为serviceSSS?

$query = $em->createQuery(
    'SELECT u
     FROM ApplicationFrontBundle:User u
          JOIN u.services s
         WHERE u.id = :id 
     '
)->setParameters(array('id'=> $id));

$services = $query->getArrayResult();