이해하는 질문이 있습니다.
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 사이에있는 모든 뉴스를 어떻게 얻을 수 있습니까? 뉴스 그룹 = 'x'(function getNews ())
/**
* Gets the groups granted to the user.
*
* @return Collection
*/
public function getNews()
{
return $this->news ?: $this->news = new ArrayCollection();
}
foreach로 각 뉴스를 살펴보고 내 조건이 맞는지 확인하는 것이 정말 필요한가요?
도움을 주셔서 감사합니다. :)
나는 당신의 조건에 따라 뉴스를 얻을 것을 제안합니다. 검색어는 다음과 같습니다.
$query = $repository->createQueryBuilder('n')
->innerJoin('n.newsgoup', 'ng')
->where('ng.id > :newsGroupId')
->where('ng.undate BETWEEN :monday AND :sunday')
->setParameter('newsGroupId', '1')
->setParameter('monday', '2016-01-02')
->setParameter('sunday', '2016-02-17')
->getQuery();
$news = $query->getResult();
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다