Given two tables:
notification
id (int PK)
title (varchar(255))
date (datetime)
notification_seen
id (int PK)
notification_id (int FK)
user_id (int FK)
user
id (int PK)
mapped as simple Doctrine entities where Notification has a relation defined as follows:
@ORM\OneToMany(targetEntity="NotificationSeen", mappedBy="notification")
private $seenBy;
and NotificationSeen:
@ORM\ManyToOne(targetEntity="Notification", inversedBy="seenBy")
@ORM\JoinColumn(name="notification_id")
private $notification;
@ORM\ManyToOne(targetEntity="User", inversedBy="seen")
@ORM\JoinColumn(name="user_id")
private $user;
and User entity:
@ORM\OneToMany(targetEntity="NotificationSeen", mappedBy="users")
private $seen;
I want to select all Notification objects which are not connected through the seenBy relation.
How to select such entities in the NotificationRepository with the QueryBuilder? Any help would be appreciated.
UPDATE:
Current method implementation in the NotificationRepository:
public function getUnreadNotification(User $user): array
{
return $this->createQueryBuilder('u')
->orderBy('u.date', 'desc')
->getQuery()
->getResult();
}