muchar
muchar

Reputation: 59

Symfony2/Doctrine2 ManyToMany DQL "has no association named" error

I'm trying to make a DQL query, which keeps giving me this error:

[Semantical Error] line 0, col 68 near 'r': Error: Class Custom\SystemBundle\Entity\Element has no association named CustomAuthBundle:Role

The code for these Entities look like this:

Role:

 /**
 * @ORM\ManyToMany(targetEntity="Custom\SystemBundle\Entity\Element", mappedBy="role_id")
 */
 private $element_id;

Element:

/**
 * @ORM\ManyToMany(targetEntity="Custom\AuthBundle\Entity\Role", inversedBy="element_id")
 */
private $role_id;

And here is the query:

php app/console doctrine:query:dql 'SELECT e FROM CustomSystemBundle:Element e JOIN e.CustomAuthBundle:Role r'

Upvotes: 0

Views: 1219

Answers (1)

Crozin
Crozin

Reputation: 44376

  1. You define your object model, so there's no place for role_id or element_id. Objects will be stored there, not their identifiers. So abc_idabc.
  2. Assocations are defined by properties, not classnames:

    […] JOIN e.role r […]
    

Upvotes: 2

Related Questions