N
N
Nikolai Gromov2017-03-22 15:04:29
Doctrine ORM
Nikolai Gromov, 2017-03-22 15:04:29

How to create a query in doctrine?

Hello! I'm trying to make a query with a union, but there is not enough knowledge.

public function findAllProductsWithCategory()
    {
    $entityManager = $this->getEntityManager();    
    $queryBuilder = $entityManager->createQueryBuilder();    
    $queryBuilder->select('p')
        ->from(Products::class, 'p')
        ->join(Category::class, 'c')
        ->where('p.category_id = c.id')
        ->orderBy('p.id', 'DESC');
    
    return $queryBuilder->getQuery();
    }

I made such a request, it initially seemed wrong to me, as if something was missing. And besides, the interpreter gives an error.
Error producing an iterator
And it is not the line in the view where the cycle begins with the object passed there from the request.
public function getIterator()
    {
        try {
            return $this->getCurrentItems();
        } catch (\Exception $e) {
            throw new Exception\RuntimeException('Error producing an iterator', null, $e);
        }
    }

This is the code that throws the exception. I climbed on the forums there they say that it is either
"date.timezone" is not set in php.ini.
or bad DQL. I believe that I have a problem with the request, because before that all requests worked fine!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shagguboy, 2017-03-22
@shagguboy

getQuery()->getResult()

S
Shirshov Alexander, 2017-03-22
@Keanor

In the docblock of the join method, an example of usage

$qb = $em->createQueryBuilder()
         ->select('u')
         ->from('User', 'u')
         ->join('u.Phonenumbers', 'p', Expr\Join::WITH, 'p.is_primary = 1');

are you joining?
Show what you are passing to the view, if you pass $queryBuilder->getQuery() there, then nothing should work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question