Doctrine期望Doctrine \ ORM \ Query \ Lexer :: T_WITH,得到','

时间:2018-06-12 18:42:43

标签: php symfony doctrine-orm doctrine php-7

在我的虚拟机中的Ubuntu服务器上,此查询(请参阅实体代码后的方法)完美地工作但在我的在线服务器上,Doctrine说这个错误:

  

[语法错误]第0行,第92行:错误:预期的Doctrine \ ORM \ Query \ Lexer :: T_WITH,得到','

这是Profile实体中的代码:

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Swagger\Annotations as SWG;

/**
 * Description of  Profile
 *
 * @ORM\Entity(repositoryClass="AppBundle\Repository\ProfileRepository")
 * @SWG\Definition(@SWG\Xml(name="profile"))
 */
class Profile
{
    /**
     * @var int $id
     *
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string $lastName
     *
     * @ORM\Column(name="lastName", type="string", length=100, nullable=false)
     * @Assert\NotBlank()
     * @Assert\Type(type="string")
     */
    private $lastName;

    /**
     * @var string $firstName
     *
     * @ORM\Column(name="firstName", type="string", length=100, nullable=false)
     * @Assert\NotBlank()
     * @Assert\Type(type="string")
     */
    private $firstName;

    /**
     * @var Company $company;
     *
     * @ORM\ManyToOne(targetEntity="Company")
     * @ORM\JoinColumn(name="company_id", referencedColumnName="id", nullable=true)
     */
    private $company;

    /**
     * @var User $user
     *
     * @ORM\ManyToOne(targetEntity="User")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
     */
    private $user;

    /**
     * @var ProfileVariety $profileVariety
     *
     * @ORM\ManyToOne(targetEntity="ProfileVariety")
     * @ORM\JoinColumn(name="profileVariety_id", referencedColumnName="id", nullable=true)
     */
    private $profileVariety;
}

配置文件存储库中的代码:

namespace AppBundle\Repository;

use Doctrine\ORM\EntityRepository;

/**
 * Description of ProfileRepository
 *
 * @package AppBundle\Repository
 */
class ProfileRepository extends EntityRepository
{
    public function findByEmail($email)
    {
        return $this->createQueryBuilder('profileByUserEmail')
            ->select('p')
            ->from('AppBundle\Entity\Profile', 'p')
            ->join('AppBundle\Entity\User', 'u')
            ->where('u.id = p.user')
            ->andWhere('u.email = :email')
            ->setParameter(':email', $email)
            ->getQuery()
            ->getResult();
    }
}

你能解释一下这个问题吗?

1 个答案:

答案 0 :(得分:4)

您应该直接加入p.user

->select('p')
->from('AppBundle\Entity\Profile', 'p')
->join('p.user', 'u')
->where('u.email = :email')

如果明确加入另一个实体类,Doctrine希望您使用WITH关键字指定JOIN条件,而不是WHERE条件:

->select('p')
->from('AppBundle\Entity\Profile', 'p')
->join('AppBundle\Entity\User', 'u', 'WITH', 'u = p.user')
->where('u.email = :email')