如何将以下SQL查询转换为Doctrine?
select * from `Leave_types`
where (leave_name = in_leave_name or leave_code=in_leave_code)
and academic_year_id =in_academic_year_id
我尝试了以下代码:
$em = $this->doctrine->em;
$qb = $em->createQueryBuilder();
$qb->select('lt');
$qb->from('Entity\LeaveTypes', 'lt');
$qb->innerjoin('lt.academicYear', 'ay');
$qb->where('ay.academicId = :academicId');
$qb->andwhere(
$qb->orWhere('leaveName', '?1'),
$qb->orWhere('leaveCode', '?2')
);
$qb->setParameter('academicId', $add_data['academic_year_id']);
$qb->setParameter(1, $add_data['leave_name']);
$qb->setParameter(2, $add_data['leave_code']);
$result = $qb->getQuery()->getResult();
答案 0 :(得分:0)
谢谢大家, 我用
解决了这个问题 $qb->where('ay.academicId = :academicId');
$qb->andWhere('lt.leaveName = :leaveName OR lt.leaveCode = :leaveCode');