0

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.

2 Answers 2

4

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)
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.