Topic: A user has many users ... but how?
I'm trying to implement a User model that would have a relationship with other users. Moreover, a user could be friends with another user.
This would be accomplished by a HABTM relationship, but I'm getting a little confused about how to set this up. The relationship would always go both ways and never one way, and would needs to be able to be searched from either side of the relationship.
Bob adds Janet. Janet and Bob are friends. (Relationship created.)
or Janet adds Bob. Bob and Janet are friends.
Bob removes Janet. Janet and Bob are no longer friends. (Relationship erased/removed)
or Janet removes Bob. Bob and Janet are no longer friends.
Bob needs to be able to see that he's friends with Janet.
Janet needs to be able to see that she's friends with Bob.
What sort of join table would be needed? user_user? That works fine in this situation because the relationship goes both ways and it doesn't matter who added who. The problem would be when searching/displaying friends. user.users wouldn't allow me to specify from what side of the relationship I'm coming from. If Bob added Janet then he could see Janet by doing user.users and she would pop up, but if Janet wanted to see that relationship she wouldn't be able to go user.users because she was the second user. No?
Would the linked table use user_a_id & user_b_id specifically as the names of the fields in the database? normally the table would be house_id & brick_id if that was the relationship, but what happens when there are relationships with each other?
Thanks for any thoughts!