2017-05-25 63 views
0

我有一個具有與畫廊關係的manyToOne實體用戶。 用戶實體與保險有關係oneToMany。 保險實體與圖庫有關係manyToOne。Symfony從兩個實體獲取畫廊

我想讓所有圖庫與用戶和用戶的保險關係。

在GalleryRepository我有這個疑問:

qb = $this->createQueryBuilder('o'); 
    $qb->select('o') 
     ->join("AppBundle:Insurance", 'i') 
     ->where(':user MEMBER OF o.userDocument') 
     ->orWhere(':user MEMBER OF o.insuranceDocument') 
     ->setParameter('user', $user); 

但這個查詢返回用戶relationated畫廊,只有一個從保險庫(該用戶有兩個保險)。

我做錯了什麼?

謝謝!

+0

也許問題是你沒有加入查詢中的用戶表。 –

+0

@MehmetSoylu謝謝你的回答。沒有加入的結果是一樣的 – RL83

+0

而不是使用或在哪裏使用和在哪裏 –

回答

0

與此查詢:

$qb->select('o') 
     ->leftJoin("AppBundle:Insurance", 'i', 'i.user = :user') 
     ->where(':user MEMBER OF o.insuranceDocument') 
     ->andWhere('i.user = :user') 
     ->setParameter('user', $user); 

我得到所有用戶的所有照片。

我要瘋了:/