*Peculiarity #1*
I have some code, like so:
$query = $this->getEntityManager()->createQuery('
SELECT i, p
FROM ' . Item::class . ' i
INNER JOIN ' . Product::class . ' p
WHERE
i.productId = p.id
');
$result = $query->getResult();
foreach ($result as $row)
print get_class($row) . ' - ' . $row->getId() . "\n"
I get this output, which is a one-dimensional array (I've added array
indices for clarity):
[0] => Application\Entity\Item - 284
[1] => DoctrineProxies\__CG__\Application\Entity\Product - 59
[2] => Application\Entity\Item - 302
[3] => Application\Entity\Item - 288
[4] => DoctrineProxies\__CG__\Application\Entity\Product - 58
[5] => Application\Entity\Item - 292
[6] => DoctrineProxies\__CG__\Application\Entity\Product - 57
I found this to be peculiar because I am requesting both "i", and "p" in my
select statement but I get count of four of "Item" returned and count of 3
of "Product".
Namely, I would typically expect 4 and 4. That is, I'd expect this line to
be present:
[2.5] => DoctrineProxies\__CG__\Application\Entity\Product - 59 --- That
line is *missing* in my output.
(Index of 2.5 to be interpreted as a made up index to signify that the line
should have been the one between indices 2 and 3)
I suspect it is because the index of the Product happens to be the same in
the join, 59 in this case)
But then I have to craft my code to accommodate for this, because normally
I'd expect the Item and Product to alternate.
Is this behavior "by design"?
*Peculiarity #2*
If I change the above DQL to say "p.model" instead, keeping everything else
the same. Like so:
SELECT i, p.model
Instead of an array of N Objects or Proxies, I now get an array of arrays.
See below (with indices for clarity):
[0][0] => Application\Entity\Item - 284
[0][1] => AA (model for id==59)
[1][0] => Application\Entity\Item - 302
[1][1] => AA (model for id==59)
[2][0] => Application\Entity\Item - 288
[2][1] => BB (model for id==58)
[3][0] => Application\Entity\Item - 292
[3][1] => CC (model for id==57)
The *inconsistency* between the structure of result sets gotten from
similar DQL statements is confusing and unexpected to me.
Is this behavior by design?
Am I using ORM correctly in this such cases?
My goal is to get the contents of Item, but also pull model from Product
Dennis
--
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 https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.