Symfony / QueryBuilder:“myEntityAlias.myEntity.id”< - 可能吗?

In short:

I'd like to fire a SQL-Query like below with something like s.item.id. Is this possible?

Entities:

class Set {
    // ...

    /**
     * @ORM\ManyToOne(targetEntity="myBundle\Entity\Item")
     * @ORM\JoinColumn(name="item_id", referencedColumnName="id")
     */
    protected $item;

    // ...
}

...

class Item {
    // ...

    /**
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue
    */
    protected $id;

    // ...
}

Repository

$sql = '
    SELECT i.id, s.name 
      FROM mybundle:Item i, mybundle:Set s 
     WHERE s.item.id = i.id <---------------------- !!!
';

return $this->getEntityManager()
            ->createQueryBuilder($sql)
            ->getResult();

Did you try it? I prefer to use the query builder functions as referenced here though. Something like this may work for you:

$qb = $em->createQueryBuilder();
$qb->select('i.id, s.name')
   ->from('mybundle:Item', 'i')
   ->leftJoin('mybundle:Set', 's', 'WITH', 's.item_id = i.id');

Edit: SQL query should be something like SELECT i.id, s.name FROM items i LEFT JOIN sets s ON s.item_id = i.id, I've edited my answer.