Home » Php » Doctrine2 Postgresql and chat system (dialogs)

Doctrine2 Postgresql and chat system (dialogs)

Posted by: admin October 26, 2017 Leave a comment



 id - primary
 author - ManyToOne User
 recipient - ManyToOne User
 createdAt - datetime

I can not think of a way to write a query that will output to me the latest messages that have been wrapped up in “dialogs”, where I am the author of the message or its recipient.

$qb = $this->em
            ->join('message.author', 'author')
            ->join('message.recipient', 'recipient')
            ->where('message.author = :person OR message.recipient = :person')
            ->setParameter('person', $person)
            ->orderBy('message.createdAt', 'DESC')

How can I add a group with the saving of sorting?

Grouping should be in the dialogues example (->addGropBy(‘author.id + recipient.id’))