Symfony createQueryBuilder oparator orX
Symfony createQueryBuilder oparator orX
我的 queryBuilder 中的这部分有问题。我需要选择开发者的参数
$qb
->andWhere($qb->expr()->like('u.roles', $qb->expr()->literal('%'.'ROLE_FREELANCER'.'%')))
->orWhere($qb->expr()->like('u.roles', $qb->expr()->literal('%'.'ROLE_DEVELOPER'.'%')));
我要更换
通过
->andWhere($qb->expr()->orX('')))
但是有很多错误,如何纠正?
public function notificationProject($paramFetcher)
{
$em = $this->getEntityManager();
$qb = $em->createQueryBuilder();
$qb
->from('ArtelProfileBundle:Users', 'u')
->select('u.id, u.email as u_email, m.email, d.skills, u.roles, m.unsubscribeDate as uns_date')
->addSelect("IF(u.roles LIKE '%ROLE_DEVELOPER%', m.email, u.email) as send_email")
->leftJoin('u.developer', 'd') //this works assuming the doctrine mappings are correct on the $developer property in the ArtelProfileBundle:Users' entity
->leftJoin('d.teams', 't')
->leftJoin('t.users', 'm')
->where('u.unsubscribeDate <= :today');
foreach ($paramFetcher[1] as $skill) {
if ($skill) {
$qb
->andWhere($qb->expr()->like('d.skills', $qb->expr()->literal('%"'.$skill.'"%')));
}
}
$qb
->andWhere($qb->expr()->like('u.roles', $qb->expr()->literal('%'.'ROLE_FREELANCER'.'%')))
->orWhere($qb->expr()->like('u.roles', $qb->expr()->literal('%'.'ROLE_DEVELOPER'.'%')));
foreach ($paramFetcher[0] as $tag) {
if ($tag) {
$qb
->andWhere($qb->expr()->notlike('d.tags', $qb->expr()->literal('%"'.$tag.'"%')));
}
}
$qb
->andWhere($qb->expr()->orX('m.unsubscribeDate <= :today', $qb->expr()->isNull('m.unsubscribeDate')))
->groupBy('send_email')
->setParameter('today', new \DateTime());
$entities = $qb->getQuery()->getArrayResult();
}
我有这个 _dql
SELECT u.id, u.email as u_email, m.email, d.skills, u.roles, m.unsubscribeDate as uns_date, IF(u.roles LIKE '%ROLE_DEVELOPER%', m.email, u.email) as send_email FROM ArtelProfileBundle:Users u LEFT JOIN u.developer d LEFT JOIN d.teams t LEFT JOIN t.users m WHERE ((u.unsubscribeDate <= :today AND d.skills LIKE '%"ASP.NET"%' AND u.roles LIKE '%ROLE_FREELANCER%') OR u.roles LIKE '%ROLE_DEVELOPER%') AND d.tags NOT LIKE '%"blacklist"%' AND d.tags NOT LIKE '%"india"%' AND d.tags NOT LIKE '%"unsubscribed"%' AND d.tags NOT LIKE '%"bounced"%' AND (m.unsubscribeDate <= :today OR m.unsubscribeDate IS NULL) GROUP BY send_email
但我 ROLE_DEVELOPER 也需要这个
(u.unsubscribeDate <= :today AND d.skills LIKE '%"ASP.NET"%' AND u.roles LIKE '%ROLE_FREELANCER%')
热衷于使用 orX 而不是这个 if 字段角色数组
->andWhere($qb->expr()->orX('')))
对于第一部分,它应该像这样工作:
发件人:
$qb
->andWhere($qb->expr()->like('u.roles', $qb->expr()->literal('%'.'ROLE_FREELANCER'.'%')))
->orWhere($qb->expr()->like('u.roles', $qb->expr()->literal('%'.'ROLE_DEVELOPER'.'%')));
收件人:
->andWhere(
$qb->expr()->orX(
$qb->expr()->like('u.roles', $qb->expr()->literal('%'.'ROLE_FREELANCER'.'%'))
, $qb->expr()->like('u.roles', $qb->expr()->literal('%'.'ROLE_DEVELOPER'.'%'))
)
)
对于直接的 DQL,为什么不只是:
(u.unsubscribeDate <= :today AND d.skills LIKE '%"ASP.NET"%' AND u.roles LIKE '%ROLE_FREELANCER%')
收件人:
(u.unsubscribeDate <= :today AND d.skills LIKE '%"ASP.NET"%' AND (u.roles LIKE '%ROLE_FREELANCER%' OR u.roles LIKE '%ROLE_DEVELOPER%'))
我的 queryBuilder 中的这部分有问题。我需要选择开发者的参数
$qb
->andWhere($qb->expr()->like('u.roles', $qb->expr()->literal('%'.'ROLE_FREELANCER'.'%')))
->orWhere($qb->expr()->like('u.roles', $qb->expr()->literal('%'.'ROLE_DEVELOPER'.'%')));
我要更换 通过
->andWhere($qb->expr()->orX('')))
但是有很多错误,如何纠正?
public function notificationProject($paramFetcher)
{
$em = $this->getEntityManager();
$qb = $em->createQueryBuilder();
$qb
->from('ArtelProfileBundle:Users', 'u')
->select('u.id, u.email as u_email, m.email, d.skills, u.roles, m.unsubscribeDate as uns_date')
->addSelect("IF(u.roles LIKE '%ROLE_DEVELOPER%', m.email, u.email) as send_email")
->leftJoin('u.developer', 'd') //this works assuming the doctrine mappings are correct on the $developer property in the ArtelProfileBundle:Users' entity
->leftJoin('d.teams', 't')
->leftJoin('t.users', 'm')
->where('u.unsubscribeDate <= :today');
foreach ($paramFetcher[1] as $skill) {
if ($skill) {
$qb
->andWhere($qb->expr()->like('d.skills', $qb->expr()->literal('%"'.$skill.'"%')));
}
}
$qb
->andWhere($qb->expr()->like('u.roles', $qb->expr()->literal('%'.'ROLE_FREELANCER'.'%')))
->orWhere($qb->expr()->like('u.roles', $qb->expr()->literal('%'.'ROLE_DEVELOPER'.'%')));
foreach ($paramFetcher[0] as $tag) {
if ($tag) {
$qb
->andWhere($qb->expr()->notlike('d.tags', $qb->expr()->literal('%"'.$tag.'"%')));
}
}
$qb
->andWhere($qb->expr()->orX('m.unsubscribeDate <= :today', $qb->expr()->isNull('m.unsubscribeDate')))
->groupBy('send_email')
->setParameter('today', new \DateTime());
$entities = $qb->getQuery()->getArrayResult();
}
我有这个 _dql
SELECT u.id, u.email as u_email, m.email, d.skills, u.roles, m.unsubscribeDate as uns_date, IF(u.roles LIKE '%ROLE_DEVELOPER%', m.email, u.email) as send_email FROM ArtelProfileBundle:Users u LEFT JOIN u.developer d LEFT JOIN d.teams t LEFT JOIN t.users m WHERE ((u.unsubscribeDate <= :today AND d.skills LIKE '%"ASP.NET"%' AND u.roles LIKE '%ROLE_FREELANCER%') OR u.roles LIKE '%ROLE_DEVELOPER%') AND d.tags NOT LIKE '%"blacklist"%' AND d.tags NOT LIKE '%"india"%' AND d.tags NOT LIKE '%"unsubscribed"%' AND d.tags NOT LIKE '%"bounced"%' AND (m.unsubscribeDate <= :today OR m.unsubscribeDate IS NULL) GROUP BY send_email
但我 ROLE_DEVELOPER 也需要这个
(u.unsubscribeDate <= :today AND d.skills LIKE '%"ASP.NET"%' AND u.roles LIKE '%ROLE_FREELANCER%')
热衷于使用 orX 而不是这个 if 字段角色数组
->andWhere($qb->expr()->orX('')))
对于第一部分,它应该像这样工作:
发件人:
$qb
->andWhere($qb->expr()->like('u.roles', $qb->expr()->literal('%'.'ROLE_FREELANCER'.'%')))
->orWhere($qb->expr()->like('u.roles', $qb->expr()->literal('%'.'ROLE_DEVELOPER'.'%')));
收件人:
->andWhere(
$qb->expr()->orX(
$qb->expr()->like('u.roles', $qb->expr()->literal('%'.'ROLE_FREELANCER'.'%'))
, $qb->expr()->like('u.roles', $qb->expr()->literal('%'.'ROLE_DEVELOPER'.'%'))
)
)
对于直接的 DQL,为什么不只是:
(u.unsubscribeDate <= :today AND d.skills LIKE '%"ASP.NET"%' AND u.roles LIKE '%ROLE_FREELANCER%')
收件人:
(u.unsubscribeDate <= :today AND d.skills LIKE '%"ASP.NET"%' AND (u.roles LIKE '%ROLE_FREELANCER%' OR u.roles LIKE '%ROLE_DEVELOPER%'))