2016-11-10 4 views
0

Doctrineのフィルタリング

SELECT company , state 
FROM employees 
WHERE 
(company, state) <> ('xxxxx', 'xxxx') 
AND 
(company, state) <> ('xxxx', 'xxxx') 
GROUP BY company, state 

私は次のようにしてみました:

$qb->andWhere($qb->expr()->andX($qb->expr()->neq('b.company',"'".$i['description']."'"), $qb->expr()->neq('b.state', "'".$i['state']."'"))); 

をしかし、結果は希望ではありません。

(company <> 'xxxxx' AND state <> 'xxxx') AND (company <> 'xxxxx' AND state <> 'xxxxx') 

最初のdoctrineはどうすればできますか? はご安心!

答えて

0

上記のクエリは2つのリストのORとして機能し、より簡単なものになります。

など。

状態または会社でない会社の

状態はありませんが、どちらかが、その後の会社+状態のその従業員の組み合わせは除外1真実ではありませんかのように。

は、あなたが以下のようにこれを実行することができ、ことを考える:

$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() 
    ; 
+0

タンクを! "ではない" 2つのリストの組合は、フィールドを結合しないだろうと信じて! @リチャード – jotamolas

+0

たとえば、「paris、acme s.a.」がある場合、そして、 "ロンドン、リバティーs.a."新しい行 "paris、liberty s.a"を入力すると、クエリはそれを返しません。 – jotamolas