I have a Rails app which has a table called friendrequests
. It looks like this:
user1_id:integer user2_id:integer hasaccepted:boolean
I'm creating an option to add friends, but a friendrequest can only be send once. So you cannot have something like this in the database's data:
user1_id | user2_id | hasaccepted
1 | 2 | false
1 | 2 | false
or
user1_id | user2_id | hasaccepted
1 | 2 | false
2 | 1 | false
The user1_id/user2_id combination must be unique, not the columns themselves, so this would be possible:
user1_id | user2_id | hasaccepted
1 | 2 | false
1 | 3 | false
Is it possible to define this in a model? How can I do this?