D
D
Dark_Dante2021-11-15 15:50:21
PHP
Dark_Dante, 2021-11-15 15:50:21

Doctrine how to get divergence of two queries?

Hello. Essence of the question.
There are two selects, you need to get their discrepancy.
I do so: On pure SQL everything works, everything is fine. And now the same on DQL. But the doctrine does not know how. Which option ... we do this:
SELECT * FROM tbl1 EXCEPT SELECT * FROM tbl2

$query1 = $this->em->createQueryBuilder()
->select('c')
->form(MyClass::class, 'c')
->getQuery()
->getDQL();

$query2 = this->em->createQueryBuilder()
->select('c')
->form(OtherMyClass::class, 'c')
->getQuery()
->getDQL();

$dql = $query1 . ' EXCEPT ' . $query2;

$this->em
->createQuery($dql)
->getResult();


Yes, it was not here. The doctrine does not know the word EXCEPT. But we are not made with a finger, it is possible to register custom language constructs, such as DATEDIFF and all that.
We make the class ExceptFunction extends FunctionNode, register it in the Dotrin config, if we request $this->em->getConfiguration() then our class can be seen there, everything is fine. But this muck all the same does not parse request. It seems that my class ExceptFunction is not called at all when parsing DQL by the internals of the doctrine. Apparently I'm doing something wrong. And I can't understand what's wrong. Tell me good people, who used this thing, what is my problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Akina, 2021-11-15
@Akina

I do it like this:
SELECT * FROM tbl1 EXCEPT SELECT * FROM tbl2

Do the table structures match?
Then
SELECT t1.*
FROM tbl1
LEFT JOIN tbl2 ON tbl1.primary_key = tbl2.primary_key
WHERE t2.primary_key IS NULL

This should map to the framework's syntax without any problems.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question