Entities
Код: Выделить всё
/**
* @ORM\Entity(repositoryClass="AppBundle\Repository\PageRepository")
* @ExclusionPolicy("all")
*/
class Page
{
/**
* @ORM\ManyToMany(targetEntity="Term", inversedBy="pages")
*/
protected $terms;
public function __construct()
{
$this->terms = new ArrayCollection();
}
/**
* @return mixed
*/
public function getTerms()
{
return $this->terms;
}
/**
* @param mixed $terms
*/
public function setTerms($terms)
{
$this->terms = $terms;
}
}
/**
* @ORM\Entity(repositoryClass="AppBundle\Repository\TermRepository")
* @ExclusionPolicy("all")
*/
class Term
{
/**
* @ORM\ManyToMany(targetEntity="Page", mappedBy="terms", cascade={"persist"}, fetch="LAZY"))
*/
protected $pages;
public function __construct()
{
$this->pages = new ArrayCollection();
}
public function getPages()
{
return $this->pages;
}
public function setPages($pages)
{
$this->pages = $pages;
}
}
Код: Выделить всё
$ignoreTermsКод: Выделить всё
$ignoreTerms = [
$this->getParameter('param1'),
$this->getParameter('param2'),
$this->getParameter('param3'),
$this->getParameter('param4'),
];
Код: Выделить всё
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('p')
->from('AppBundle:Page', 'p')
->leftJoin('p.terms','tt'); // probably wrong use of join here
if(!empty($limit))
$qb->setMaxResults($limit);
if (!empty($ignoreTerms)) {
$qb->andWhere(
$qb->expr()->notIn('tt.id', $ignoreTerms)
);
}
return $qb;
Код: Выделить всё
SELECT p0_.*
FROM page p0_ LEFT JOIN page_term p2_ ON p0_.id = p2_.page_id
LEFT JOIN term t1_ ON t1_.id = p2_.term_id
WHERE t1_.id NOT IN (--the array here--)
ORDER BY p0_.`publishDate`
DESC LIMIT 15 OFFSET 0
Я ожидаю, что он также будет извлекать страницы с условиями или без них.
Доступные методы объединения являются
Код: Выделить всё
join()Код: Выделить всё
innerJoin()Код: Выделить всё
leftJoin()
Подробнее здесь: https://stackoverflow.com/questions/790 ... other-data