I have an object pagethat consists of several containers. In these containers, the user can bind a news list. Those news listcontain again news items.
Now I want to search news items, but I need pageand news listalso connected.
I tried this:
$query = $this->getEntityManager()->createQuery('
SELECT p, c, n, i
FROM VendorNameBundle:Page p
LEFT JOIN p.container c
LEFT JOIN c.news n
LEFT JOIN n.items i
WHERE i.title LIKE :title
GROUP BY i.id
');
Which basically works, as it gives me the correct page. But in order to find the right one news item, I would have to run through everything containerand their news lists. And of course, when I retrieve the elements, I get everything, and not just one important thing for the search.
How can I solve this in an elegant way?
: news items page. ?
. a news list , page , .
Edit
:
PAGE
/**
* @ORM\OneToMany(targetEntity="Container", mappedBy="page", cascade={"remove"})
* @ORM\OrderBy({"position" = "asc"})
*/
protected $containers;
/**
* @ORM\ManyToOne(targetEntity="Page", inversedBy="containers")
* @ORM\JoinColumn(name="Page_id", referencedColumnName="id")
*/
private $page;
/**
* @ORM\ManyToOne(targetEntity="News", inversedBy="containers")
* @ORM\JoinColumn(name="news_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $news;
protected $containers;