From: "Jasper N. Brouwer" <jas...@nerdsweide.nl>
Date: Wed, 7 Nov 2012 17:25:21 +0100
Local: Wed, Nov 7 2012 11:25 am
Subject: Re: [doctrine-user] ManyToMany with extra field, limit results
When joining 2 (or more) entities, you cannot limit on root-entities only. You will have to do this in 2 steps:
In your case I suspect you want to reduce the number of queries needed to get the results (I don't see a WHERE statement). You could do it this way:
$q = $em->createQuery( 'SELECT a.id FROM Articulo a ORDER BY a.fecha DESC' );
$ids = $q->getArrayResult();
$q = $em->createQuery( 'SELECT a, au, u FROM Articulo a LEFT JOIN a.autores au JOIN au.usuario u WHERE a.id IN :ids ORDER BY a.fecha DESC' );
$result = $q->getResult();
PS: If you are doing this for pagination, take a look at http://docs.doctrine-project.org/en/latest/tutorials/pagination.html
-- On 07-11-2012, at 17:04, Guga <gustavobu...@gmail.com> wrote:
> Hi
> Is there someone what can help me? I have a ManyToMany relationship with extra fields, my schema is this one (I'm using Symfony2):
> Articulo -> articles
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> public function __construct()
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> /**
> // extras...
> /**
> If in my respository ArticuloRepository I do:
> $articulos =
> All is Perfect!! But, if I set a ->setMaxResult(10) (LIMIT 10), it return me 2 articles, with 5 authors each one, because, is applying the limit to all the registers, and not only to articles, any help?
> Thanks a lot, and sorry my english!
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||