I have 3 Entities in doctrine:
Listitem:
class Listitem
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue()
*/
protected $id;
...
}
Item:
class Item
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue()
*/
protected $id;
...
}
and ListitemOrder
/**
* Class ListitemOrder
* @package AppBundle\Entity
* @ORM\Table(name="listitem_order",uniqueConstraints={@ORM\UniqueConstraint(name="uq_listitem_item", columns={"listitem_id", "item_id"})})
* @ORM\Entity(repositoryClass="AppBundle\Repositories\ListitemOrderRepository")
*/
class ListitemOrder
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue()
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Listitem")
*/
protected $listitem;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Item")
*/
protected $item;
/**
* @ORM\Column(type="integer")
*/
protected $order;
...
}
My lists have items, but it's possible that the items belong to other list, in diferent order. Because that I need the ListitemOrder
entity.
When i want to get the items ordered of one list, I have one query like that:
$qb->select(array('l', 'i'))
->from('AppBundle:ListitemOrder', 'l')
->leftJoin("l.item", 'i')
->where('l.listitem = :listitem')->setParameter("listitem", $listitem)
->orderBy("l.order", 'DESC')
;
I think that this is correct, but when I want call this function, my browser and my vagrant vm dies. I think that it's happend because Doctrine get the informacion recursively and never ends. I mean, Item information, and the List, and the Items of the list, and the list of the items... It's possible?
The query generated is like this:
SELECT l0_.id AS id0, l0_.order AS order1, l0_.listitem_id AS listitem_id2, l0_.item_id AS item_id3
FROM listitem_order l0_
LEFT JOIN item i1_ ON l0_.item_id = i1_.id
WHERE l0_.listitem_id = 1
ORDER BY l0_.order DESC
LIMIT 25 OFFSET 0