Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine2 expressions eq special char for matching all

I am trying run filters with doctrine query builder, i am using expr eq, but if i don´t have filter value, i would like to use some special symbol for expr eq which returs all rows.

my code:

$q = $qb->select(array('p'))
                ->from(payment::class, 'p')
                ->innerJoin(customer::class, 'z', 'WITH', 'p.customer= z.id')
                ->where(                            
                        $qb->expr()->eq('z.id', '?2')
                )
                ->setMaxResults($limit)
                ->setFirstResult($offset)
                ->orderBy('p.'.$sortField, $sortType) 

there i want somting like(->setParameter(2, "*"))

                ->setParameter(2, $filtry['customer'])
                ->getQuery();

        return $q->getResult();

Is it possible? I don´t want write different query builder for each filter.

Sorry for my English

Thanks

like image 914
Hancs Avatar asked Oct 18 '22 03:10

Hancs


1 Answers

It's a query builder so you can add params conditionally, as example:

$qb->select(array('p'))
                ->from(payment::class, 'p')
                ->innerJoin(customer::class, 'z', 'WITH', 'p.customer= z.id')
                ->setMaxResults($limit)
                ->setFirstResult($offset)
                ->orderBy('p.'.$sortField, $sortType) 


if ($filtry['customer'])
{
$qb->andWhere(                            
              $qb->expr()->eq('z.id', $filtry['customer'])
                )
};

$q = $qb->getQuery()

Hope this help

like image 146
Matteo Avatar answered Oct 27 '22 09:10

Matteo