mysql - QueryBuilder and sub-conditions -
hi i'm tring build query using querybuilder
, query\expr
. probleme build sub condition in order list of model of conditions ?
status
true
, not in list ofmodel
namestatus
false
, not in other list ofmodel
name
code :
public function process(querybuilder $qb) { $cond1 = new expr\andx; $cond1->add($qb->expr()->eq('status', 0); $cond2= new expr\andx; $cond2->add($qb->expr()->notin('model', array('308','408')); $cond1->add($cond2); $cond3 = new expr\andx; $cond3->add($qb->expr()->eq('status', 1); $cond4= new expr\andx; $cond4->add($qb->expr()->notin('model', array('a1','a2')); $cond3->add($cond4); $qb->andwhere($cond1); $qb->andwhere($cond3); }
class model
class vehicle{ /** * @var string * * @orm\column(name="model", type="string", length=255, nullable=true) */ private $modele; /** * @var string * * @orm\column(name="make", type="string", length=255, nullable=true) */ private $make; /** * @var boolean (status vehicule 1 = used vehicle) * * @orm\column(name="status", type="boolean") * @serializer\groups({"list", "details"}) */ private $status; //-- other properties, getter & setter }
thanks help
$qb->andwhere( $qb->expr()->andx( $qb->expr()->andx( $qb->expr()->eq('status', 0), $qb->expr()->andx( $qb->expr()->notlike('model', '308'), $qb->expr()->notlike('model', '408') ) ), $qb->expr()->andx( $qb->expr()->eq('status', 1), $qb->expr()->andx( $qb->expr()->notlike('model', 'a1'), $qb->expr()->notlike('model', 'a2') ) ) ) );
you can go wild nesting expressions long read docs
let me know if need :)
Comments
Post a Comment