QueryBuilder 中的 Symfony OneToOne Doctrine

Symfony OneToOne Doctrine like in QueryBuilder

像 symfony 的查询构建器一样不起作用并向我显示错误!

这是我的查询:

    $apiToken = $this->createQueryBuilder('ud')
        ->select('ud.apiToken')
        ->where('ud.user LIKE :userPhone')
        ->setParameter('userPhone','%'.$phone)
        ->getQuery()
        ->getResult();

    return $apiToken;

这是错误:

[Semantical Error] line 0, col 64 near 'user LIKE :u': Error: Invalid PathExpression. Must be a StateFieldPathExpression.

无法在查询生成器或有用的描述中找到任何扩展内容!

这是我的用户设备实体:

class UserDevice implements UserInterface, \Serializable
{
    /**
     * @var int
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\Column(name="notification_token",type="string", nullable=true)
     */
    private $notificationToken;

    /**
     * @ORM\Column(name="api_token" , type="string", unique=true, nullable=true)
     */
    private $apiToken;

    /**
     * @ORM\OneToOne(targetEntity="User", inversedBy="device", fetch="EAGER")
     * @ORM\JoinColumn(name="user_phone", referencedColumnName="phone")
     */
    private $user;

}

您应该在 table UserDeviceUser 之间使用 join 查询。

$apiToken = $this->createQueryBuilder('ud')
        ->select('ud.apiToken')
        ->where('u.phone LIKE :userPhone') // here Users phone field
        ->innerJoin('ud.user', 'u')
        ->setParameter('userPhone','%'.$phone)
        ->getQuery()
        ->getResult();

return $apiToken;