доктрина создать запрос с 2 ассоциациями

у меня есть эта сущность

Почта

 /**
 * @ORM\ManyToOne(targetEntity="SottoCategoria")
 * @ORM\JoinColumn(name="sottocategoria_id", referencedColumnName="id", nullable=false)
 */
public $sottocategoria;

SottoCategoria

 /**
 * @ORM\ManyToOne(targetEntity="Categoria")
 * @ORM\JoinColumn(name="categoria_id", referencedColumnName="id", nullable=false)
 */
public $categoria;

Категория

/**
 * @ORM\OneToMany(targetEntity="SottoCategoria", mappedBy="categoria")
 */
protected $sottocategorie;

как я могу сделать этот запрос? мне нужно найти все сообщения из категории

post.sottocategoria.categoria

 $query = $repository->createQueryBuilder('p')
                    ->where('p.enabled = :enabled AND p.sottocategoria.categoria = :categoria')
                    ->setParameters(array(
                        'enabled' => true,
                        'categoria' => $idCat,
                    ))

я не могу использовать p.categoria, потому что я не имею отношения к почте

мое отношение - сообщение -> sottocategoria -> категория, поэтому мой вопрос в том, как я могу получить все сообщения из категории? я должен использовать внутреннее соединение?


person Pulcino Pio    schedule 14.01.2013    source источник


Ответы (1)


$em = $this->getDoctrine()->getEntityManager(); $query = $em->createQuery( 'ВЫБЕРИТЕ p,g,c ИЗ AcmeBlogBundle:Post p ПРИСОЕДИНЯЙТЕСЬ к p.sottocategoria g ПРИСОЕДИНЯЙТЕСЬ к g.categoria c ГДЕ p.enabled = :enabled И g.categoria = :categoria ORDER BY p.id DESC')

решено

person Pulcino Pio    schedule 14.01.2013