I have a chatrooms
and a users
table joined via a chatroom_members
table
I am modeling “private” chatrooms as being chatrooms with type: :private
and exactly 2 chatroom_members
. Private chatrooms are unique via their chatroom_members
, i.e. 2 users can have no more than 1 private chatroom together.
Given the following records
chatroom
— id:1, type: :private
chatroom_member
— chatroom_id: 1, user_id: 100
chatroom_member
— chatroom_id: 1, user_id: 200
How do i check on insert chatroom whether a chatroom already exists with only and exactly those 2 user_id
's in the associated chatroom_members
?