我有这个实体
帖子
/**
* @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,因为我和post没有关系
我的关系是->分类->,所以我的问题是如何从分类中获取所有的帖子?我必须使用innerjoin吗?
发布于 2013-01-15 06:51:10
$em = $this->getDoctrine()->getEntityManager();$query = $em->createQuery( 'SELECT p,g,c FROM AcmeBlogBundle:Post p JOIN p.sottocategoria g JOIN g.categoria c WHERE p.enabled = :enabled AND g.categoria = :categoria ORDER BY p.id DESC')
已解决
https://stackoverflow.com/questions/14327406
复制相似问题