Shahzad Intersoft
Shahzad Intersoft

Reputation: 772

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.

Upvotes: 0

Views: 110

Answers (2)

Juan I. Morales Pestana
Juan I. Morales Pestana

Reputation: 1147

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...

Upvotes: 0

Mert Simsek
Mert Simsek

Reputation: 1560

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)

Upvotes: 4

Related Questions