KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm currently working on a small social networking application and right now I'm trying to create a model that represents friendships between users . This is what I came up with so far: class User < ActiveRecord::Base # ... has_many :friendships has_many :friends, :through => :friendships end class Friendship < ActiveRecord::Base belongs_to :user belongs_to :friend, :class_name => 'User' end My friendship model has a field confirmed as boolean which I'd like to use to define a friendship as pending or confirmed. How can I access all pending request for a certain user? Can I somehow define this using Rails' scope method? Something like current_user.friendships.requests # => [Friendship, Friendship, ...] would be great. How can I make this association bidirectional? Do I simply add another friendship once one has confirmed a friend request such that my friendship table would look similar to this: | user_id | friend_id | confirmed | ----------------------------------- | 1 | 2 | true | | 2 | 1 | true |
Tags (comma-separated)
Save Edits
Cancel