symfony - Doctrine filtering by multiple columns -
i need filter in doctrine through multiple fields following:
select company , state employees (company, state) <> ('xxxxx', 'xxxx') , (company, state) <> ('xxxx', 'xxxx') group company, state i tried following way:
$qb->andwhere($qb->expr()->andx($qb->expr()->neq('b.company',"'".$i['description']."'"), $qb->expr()->neq('b.state', "'".$i['state']."'"))); but result not desired:
(company <> 'xxxxx' , state <> 'xxxx') , (company <> 'xxxxx' , state <> 'xxxxx') how can first via doctrine? regards!
that query above work or of 2 lists make things simpler you.
e.g.
where state not in states or company not in companies
as if either true employee's combination of company + state not excluded one.
given that, run below:
$qb = $this->getentitymanager()->createquerybuilder(); $excludedcompanies = ['company1', 'another company', 'company etc']; $excludedstates = ['state1', 'another state', 'state etc']; return $qb->select('e.company, e.state') ->from('yourbundle:employee', 'e') ->where($qb->expr()->notin('e.company', ':excludedcompanies')) ->orwhere($qb->expr()->notin('e.state', ':excludedstates')) ->setparameter('excludedcompanies', $excludedcompanies) ->setparameter('excludedstates', $excludedstates) ->groupby('e.company') ->addgroupby('e.state') ->getquery() ->getresult() ;
Comments
Post a Comment