I got a understanding question.
I got 2 mapped Entities
class news
{
public function __construct()
{
$this->newsgroups = new ArrayCollection();
}
/**
* @ORM\ManyToMany(targetEntity="Unite\NewsBundle\Entity
ewsgroup", inversedBy="news")
* @ORM\JoinTable(name="news_to_newsgroup")
**/
protected $newsgroups;
....
}
And
class newsgroup
{
public function __construct()
{
parent::__construct();
$this->news = new ArrayCollection();
}
/**
* @ORM\ManyToMany(targetEntity="Unite\NewsBundle\Entity
ews", mappedBy="newsgroups", cascade={"detach"})
* @ORM\OrderBy({"undate" = "DESC"})
**/
protected $news;
....
}
My question: how can i get all news which are active and between date x and y WHERE newsgroup = 'x' when i'm using my newsgroup object (function getNews())
/**
* Gets the groups granted to the user.
*
* @return Collection
*/
public function getNews()
{
return $this->news ?: $this->news = new ArrayCollection();
}
Is it realy necessary to go through each news with a foreach and check if my conditions are true?
Thanks a lot my friends for your help :)