Trying to Create a Friend System

I’m trying to add the ability to add other users of my app as friends
(to follow their recent activity, etc.), however I can’t grasp what
ActiveRecord association should be used. Basically, I’ve tried to do
this:

class User < ActiveRecord::Base
has_one :user_picture
has_many :scores
has_many :friendships
end

class Friendship < ActiveRecord::Base
belongs_to :user
end

And my friendships table looks like this:
create_table :friendships, :force => true do |t|
t.column “user_id”, :integer, :null => false
t.column “friend_id”, :integer, :null => false
end

User_id holds the ID of the user that added another user as friend,
and friend_id is the ID of the user that was added as a friend (sorry
if this sentence didn’t make much sense).

All I need to do is track who is friends of who, and see if their
friendship is mutual. If I keep working on it, the code above can
probably work, but it doesn’t seem to Railsy. So if you can, please
let me know how you would pull this sort of thing off.

Thanks for taking a look,
Tony

On 29 Jun 2007, at 03:49, TeeC wrote:

end

Tony

I’m no guru on Railsyness, but I wonder if the tables you describe
are capturing all of what’s happening in your relationships. Your
last paragraph implies that friendship is mutual – and thus exists
only when both requested and accepted, requiring two steps to create.
As I read this, the friendships table holds both requests and
accepted friendships. Separating them might make this easier and more
transparent to manage…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs