I am pretty new to SQL and typeORM, and I especially have troubles when it comes to many to many relationships.
I am working on a chat application. I have two tables connected by a many to many to many relationship.
========= =========
| Room | | User |
========= =========
| id | -< | id |
--------- / ---------
| type | / | ... |
--------- / ---------
| User[]| >--
---------
| ... |
---------
Room.type can be of value dm, private or public
I also have a join table in between the two tables, but it is handled by typeORM so I don't really care about it.
What I want to do is to query the Room table and get all the rooms of type dm where the user are exactly user1_id and user2_id (no more, no less) but I really don't know how to formulate this query. Something like:
SELECT * FROM 'Room'
WHERE type IS 'dm'
AND WHERE 'user1_id' IN 'User.id'
AND WHERE 'user2_id' IN 'User.id'
AND WHERE LENGTH(Room.User) = 2
I am posting this with SQL but eventually I will translate it with typeORM syntax which should not be a problem.
Thanks.