2012-09-30 52 views
0

我試圖做一個DQL查詢,這一直給我這個錯誤:的Symfony2/Doctrine2多對多DQL「沒有協會命名」錯誤

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

這些實體的代碼如下所示:

角色:

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

元素:

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

這裏是查詢:

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

回答

2
  1. 定義你的對象模式,所以有一個爲role_idelement_id的地方。對象將被存儲在那裏,而不是它們的標識符。所以abc_idabc
  2. 關聯設定由性能,而不是類名定義:

    […] JOIN e.role r […] 
    
+0

是啊,我剛剛得到了一分鐘前。謝謝您的回答! – muchar