I have the following entities:
@Entity
class User {
@ManyToMany(type => Group)
@JoinTable()
groups: Group[];
}
@Entity
class MediaObject {
@ManyToMany(type => Group)
@JoinTable()
groups: Group[];
}
@Entity
class Group {
// [...]
}
Now I want to select every MediaObject which has at least one group in common with the one specific User.
Example:
User 1 MediaObject 1
-----------------------------
Group 1 |--- Group 2
Group 2 ---| Group 3
User 1 has at least one same group as MediaObject
How can I build a where sql query for this? I use typeorm for building my queries, yet every sql query would help. Also, I want to understand how. Typeorm joins the tables like this
LEFT JOIN "group" "groups" ON "groups"."id" = "media_groups"."groupId"