Symfony2-如果没有leftJoin语句,如何重写此条令查询

Symfony2-如果没有leftJoin语句,如何重写此条令查询,symfony,doctrine-orm,Symfony,Doctrine Orm,我正在使用查询按类型选择帖子。这与要发布的类型具有一对一/多对一关系 如何在不使用leftJoin语句的情况下重写此语句 此查询可以工作并按类型标题获取post,但如果不需要联接,则希望重新编写该查询 质疑 职位 类型 您可以通过Typeid选择Post,如下所示: public function getPostsByType($type) { return $this->createQueryBuilder('post') ->where('post.type =

我正在使用查询按类型选择帖子。这与要发布的类型具有一对一/多对一关系

如何在不使用leftJoin语句的情况下重写此语句

此查询可以工作并按类型标题获取post,但如果不需要联接,则希望重新编写该查询

质疑

职位

类型


您可以通过
Type
id
选择
Post
,如下所示:

public function getPostsByType($type)
{
    return $this->createQueryBuilder('post')
    ->where('post.type = :typeId')
    ->setParameter('typeId', $type->getId())
    ->orderBy('post.createdAt', 'DESC')
    ->getQuery()
    ->getResult();
}
/**
 * @ORM\ManyToOne(targetEntity="Type", inversedBy="posts")
 * @ORM\JoinColumn(name="type_id", referencedColumnName="id")
 */
protected $type;
/**
 * @ORM\OneToMany(targetEntity="Post", mappedBy="type")
 */
protected $posts;
public function getPostsByType($type)
{
    return $this->createQueryBuilder('post')
    ->where('post.type = :typeId')
    ->setParameter('typeId', $type->getId())
    ->orderBy('post.createdAt', 'DESC')
    ->getQuery()
    ->getResult();
}