Answer the question
In order to leave comments, you need to log in
how to make self join in Doctrine 2 without specifying explicit links?
There is an abstract entity. For example, news. With each editing, we create a new news item in the database with a certain number, different text and a new date. Suppose we have three fields for this. (id, newsId, text, date).
without id we are nowhere, but it doesn't matter. All this works great.
And now I need to make a selection of such a plan:
Voooot ... that is, pull out two news items with the same ID, but with consecutive dates. Naturally, since the relationship between news is not described in the ORM model, the Query Builder swears.
" Identification Variable testBundle\Entity\news used in join path expression but was not defined before. "(c)
em->createQuery("select news1, news2 from
testBundle\Entity\news news1
left join
testBundle\Entity\news news2
on (news1.newsId=news2 .newsId)
where news1.date ='today' and news2.date ='1 day ago')
->setMaxResults(10)
->getResult();
I still smoke Versionable, but I don’t want to redo what I already have. The SQL query has been compiled, but I can’t figure out how to “squeeze” it into the ORM.
CHADNT?
Answer the question
In order to leave comments, you need to log in
Literally did exactly the same thing today. It's possible. There are several solutions to the problem. You can suffer with DQL, or you can write through Native SQL. The second option always works, but you will also have to describe the mapping of the results (it's not tricky, but tiring).
Although in your case it would be more logical to use some kind of entity versioning extension .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question