Say User A is connected to B, then user B is automatically considered to be connected with user A.
User has_many connection
Connection Table:
id, user_id, connected_user_id
Say
id || user_id|| connected_user_id
1 || 1 || 2
2 || 3 || 1
3 || 2 || 3
Expected outcome:
User.find(1).connections
[< User id:2, ... >,< User id:3, ... > ]
User.find(2).connections
[< User id:1, ... >, < User id:3, ... >]
If you need a many-to-many relationship, which it sounds like you do, you can set up a has_many through relationship:
Then to find all connections like you want you can create a method in your User class:
User.find(1).get_connectionsshould return