-1

I have two netities user & service and the join table user_service generated by doctrine, i tried to add a manytomany relatioship here is the annotations that i added :

Entity User side :

/**
* @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;

Entity Service side :

/**
 * @ORM\ManyToMany(targetEntity="User", mappedBy="services")
 */
protected  $users;

Everything seems to work fine, but when i make this request :

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

    $services = $query->getArrayResult();

I have this error :

[Semantical Error] line 0, col 91 near 's
': Error: Class Application\FrontBundle\Entity\User has no association named service

But when i do it by the objects it works, the problem is that it executes a lot of requests

j0k
  • 22,600
  • 28
  • 79
  • 90
sibko1
  • 3
  • 3

1 Answers1

0

Because you named it 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();
gremo
  • 47,186
  • 75
  • 257
  • 421
  • Thank you very much :) !!!!, ahaa so the join must refer to name of the variable that contains other side entities :) – sibko1 Aug 05 '12 at 12:21
  • @sibko1 yes, to the name of the "association" (that is, the variable). – gremo Aug 05 '12 at 12:23