我有一個理解的問題。Symfony獲得與語句映射實體(where子句)
我得到了2個映射實體
class news
{
public function __construct()
{
$this->newsgroups = new ArrayCollection();
}
/**
* @ORM\ManyToMany(targetEntity="Unite\NewsBundle\Entity\newsgroup", inversedBy="news")
* @ORM\JoinTable(name="news_to_newsgroup")
**/
protected $newsgroups;
....
}
而且
class newsgroup
{
public function __construct()
{
parent::__construct();
$this->news = new ArrayCollection();
}
/**
* @ORM\ManyToMany(targetEntity="Unite\NewsBundle\Entity\news", mappedBy="newsgroups", cascade={"detach"})
* @ORM\OrderBy({"undate" = "DESC"})
**/
protected $news;
....
}
我的問題: 我怎樣才能得到所有的新聞有活性和日期X和Y之間WHERE新聞組= 'X' 當我使用我的新聞組對象(函數getNews())
/**
* Gets the groups granted to the user.
*
* @return Collection
*/
public function getNews()
{
return $this->news ?: $this->news = new ArrayCollection();
}
是否真的需要通過foreach來檢查每條新聞並檢查我的條件是否屬實?
非常感謝我的朋友們對你的幫助:)
感謝您的回答,我正在考慮這種方式。我認爲還有另外一種方法可以從多元映射理論中獲得。所以它就像正常的msqli命令與教條一樣。非常感謝你:) – cRsakaWolf
哈工作:D - innerJoin自動映射到新聞組,因爲許多映射。完善!謝謝 – cRsakaWolf