我有一个下表结构查询不能
表:医生
id name
1 Mac
2 Smit
表:组织
id name
1 Org1
2 Org2
表:org_doctors
id org_id doctor_id
1 1 1
2 1 2
表:专业化
id name
1 ENT
2 Cardiac
表:doc_specialzations
id doctor_id specialzation_id
1 1 1
2 1 2
3 2 1
下面是教条的代码我在工作:
$qb = $this->entityManager->createQueryBuilder();
$qb2 = $qb;
$qb2->select('dsp.doctor_id')
->from('Doctor\Entity\DoctorSpecialization', 'dsp')
->where('dsp.specialization = :specializationId')
->setParameter('specializationId', $searchBy['specialization']);
$qb->select('od', 'd', 'o', 'u')
->from('Doctor\Entity\OrgDoctor', 'od')
->leftJoin('od.organization', 'o')
->leftJoin('od.doctor', 'd')
->leftJoin('d.user', 'u');
$qb->where($qb->expr()->in('od.doctor', $qb2->getDQL()));
$qb->andWhere('od.organization IN (:organizations)')
->andWhere('d.active = true')
->andWhere('od.active = true')
->setParameter('organizations', $organizations);
在abvoe代码工作的时候,我正在以下错误:
[Syntax Error] line 0, col 188: Error: Expected Doctrine\\ORM\\Query\\Lexer::T_FROM, got ','
这是我DoctorSpecialization实体:
/**
* @ORM\Entity
* @ORM\Table(name="doctors_specializations")
*/
class DoctorSpecialization extends BaseEntity{
/**
* @ORM\ManyToOne(targetEntity="Doctor\Entity\Doctor", inversedBy="docSpecialization")
* @ORM\JoinColumn(name="doctor_id",referencedColumnName="id",nullable=false)
*/
protected $doctor;
/**
* @ORM\ManyToOne(targetEntity="Doctor\Entity\Specialization", inversedBy="docSpecialization")
* @ORM\JoinColumn(name="specialization_id", referencedColumnName="id", nullable=false)
*/
protected $specialization;
public function setDoctor(Doctor $doctor = null)
{
$this->doctor = $doctor;
return $this;
}
public function getDoctor()
{
return $this->doctor;
}
public function setSpecialization(Specialization $specialization = null)
{
$this->specialization = $specialization;
return $this;
}
public function getSpecialization()
{
return $this->specialization;
}
}
这个错误意味着你有一个synthax错误的地方,尝试找出问题将帮助ü。 –