N
N
Nikolai Egorov2019-02-15 22:02:34
symfony
Nikolai Egorov, 2019-02-15 22:02:34

How to build a query in QueryBuilder in parts?

Where can I see a good example of building a query/s with a QueryBuilder from "pieces"? I don't know how to put it more clearly. The topic was found by me here https://symfonycasts.com/screencast/symfony-doctri... but only on the example of one method:

private function addIsPublishedQueryBuilder(QueryBuilder $qb)
    {
        return $qb->andWhere('a.publishedAt IS NOT NULL');
    }

... for a clear understanding of this technique, the example given in the article is not enough for me.
I would be very grateful if someone shares their experience. You are welcome! :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
grinat, 2019-02-15
@nickicool

I suspect that the fluent interface was meant by the pieces, something like this then:
$qb->andWhere('a.publishedAt IS NOT NULL')
->andWhere('a.status = :status')
->setParameter('status' , 'gggg');
if ($hhh === $bbb) {
$qb->andWhere('a.hhh = 1')
}
return $qb;

D
Dmitry, 2019-02-15
@Compolomus

I wrote a builder, this is not a thankful job
About five years ago there was a wrapper around mysqli with fetch and other things
. Then I decided to go only to the builder
https://github.com/Compolomus/SQLQueryBuilder
There is a lot of magic there. But the principle must be clear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question