Hi,
On 25 September 2014 18:22, Mickael Zhu <[email protected]> wrote:
> My english may be not very good.
>
>
>
> I have 4 entities class, EntityA, EntityB, EntityC and EntityD
>
> EntityA has many EntityB, the field is $bs
> EntityA has many EntityC, the field is $cs
> EntityA has many EntityD, the field is $ds
>
>
> If I do something like that :
>
> <?php
>
> $as = $em->getRepository('EntityA')->findAll();
>
> foreach($as as $a) {
> foreach($as->getBs() as $b) {
> // code
> }
> foreach($as->getCs() as $c) {
> // code
> }
> foreach($as->getDs() as $d) {
> // code
> }
> }
> ?>
>
>
> I get like 1+N*3 query.
>
>
>
> If I do
> <?php
> $em->getRepository('EntityA')
> ->createQueryBuilder('a')
> ->select('a, b, c, d')
> ->leftJoin('a.bs', 'b')
> ->leftJoin('a.cs', 'c')
> ->leftJoin('a.ds', 'd')
> ->getQuery()->execute();
>
> ?>
>
>
> Bingo, I have only 1 query, but I don't know if it's really efficient.
>
> Because doctrine will probably translate it as simple sql join.
> Mysql will probably return N^4 rows. Sure, doctrine orm will hydrate it,
> and drop duplicate rows.
>
> But for the worst case scenario, if I have like 100 entityA, each one has
> 100 entityB, 100 entityC and 100entityD,
> the database will return like 100.000.000 rows.
>
> I have found this post :
> http://www.doctrine-project.org/jira/browse/DDC-1149
> I am using master, but it doesn't seems to works.
>
>
>
> In doctrine 1, there was a nice feature, but I didn't found the same
> feature in doctrine 2.
>
> http://doctrine.readthedocs.org/en/latest/en/manual/component-overview.html#loading-related-records
> It was nice because I can get all records, with only 4 queries.
>
>
> Someone have a way to fix this issue in doctrine 2?
>
> Can you abstract your problem into a test case?
I am fairly sure that we have this solved somewhere already, so having the
problem abstracted into a reproducible phpunit test case, it would be
really useful to help you with debugging it.
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.