title: How to make a UNION with Doctrine?
body: <p>I'm trying to do the following query:    </p>
  
  <pre><code>    public function findByNotifications($ownerId)
      {
          $em = $this-&gt;getEntityManager();
          $query = $em-&gt;createQuery('
             SELECT n FROM
              (SELECT n FROM DelivveWebBundle:UserAd n
                  INNER JOIN n.ad ad
                      WHERE ad.owner = :ownerId
                  LIMIT 20
              UNION
              SELECT n FROM DelivveWebBundle:UserAd n
                  INNER JOIN n.user u
                  INNER JOIN n.ad ad
                     WHERE u.id = :ownerId
                         AND ad.status = :progress
                  LIMIT 20)
             notofication
             LIMIT 20;
          ')-&gt;setParameter('ownerId', $ownerId)
              -&gt;setParameter('progress', Constant::AD_IN_PROGRESS);
  
          $result = $query-&gt;getResult();
  
          return $result;
      }
  </code></pre>
  
  <p>to generate all my notifications:</p>
  
  <pre><code>    public function showNotificationsAction()
      {
          $this-&gt;denyAccessUnlessGranted('ROLE_USER', null, 'Unable to access this page!');
  
          $owner = $this-&gt;getUser();
  
          $repository = $this-&gt;getDoctrine()-&gt;getRepository('DelivveWebBundle:UserAd');
  
          $notifications = $repository-&gt;findByAdOwner($owner-&gt;getId());
  
          return $this-&gt;render('DelivveWebBundle:Ad:notification.html.twig', array(
              'owner' =&gt; $owner,
              'notifications' =&gt; $notifications
          ));
      }
  </code></pre>
  
  <p>The idea is to do a search on AdUser table that returns all notifications that have ads that logged User owns, along with any notifications that logged User requested.</p>
  
  <p>Notification the User requested is a line of AdUser table that has the column the user logged in User.</p>