简体   繁体   中英

How to use IS NOT NULL in Associative Array

I am new in Symfony framework And I want to use Query basis on Condition

which is using associative array and I want to use IS NOT NULL But it is not

working.

$repository = $this->getDoctrine()->getRepository('AppBundle:Order');
$order = $repository->findBy(array('status' => $last_status,'new_coloumn_id'=>"IS NOT NULL"));

How to use IS NOT NULL in array.

You should add custom function into your Order Repository file(class). Example;

public function getOrderStatus($last_status = NULL){
    $query = $this->createQueryBuilder('order')
        ->where('order.new_column_id IS NOT NULL')
        ->andWhere('status = :status')
        ->setParameter('status', $last_status);

    return $query->getQuery()->getResult();
}

And you can use it;

$order = $this->getDoctrine()->getRepository('AppBundle:Order')->getOrderStatus($last_status)

Try this in your repository class:

public function findOrder($last_status){
        $qb = $this->createQueryBuilder('order');

        return $qb->where($qb->expr()->isNotNull('order.new_column_id'))
            ->andWhere($qb->expr()->eq('order.status',':last_status'))
            ->setParameter('last_status',$last_status)
            ->getQuery()
            ->getOneOrNullResult();//getArrayResult,getResult()

    }

hope it helps...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM