4

Using Mongo and Rails, I would to build a friendship system like facebook: - Before making the friendship, the use must accept the friendship request

I found a lots of code to do the relationship but never with a relation's property...

Do you have any idea or clue how to do that to be "respectful" of the NoSQL concept

Thank you for your help

DJYod
  • 237
  • 3
  • 9

2 Answers2

11

Just use two models, something like this:

class User
  include Mongoid::Document
  has_many :friendships
end

class Friendship
  include Mongoid::Document
  belongs_to :owner, :class_name => "User"
  belongs_to :friend, :class_name => "User"
  field :pending, :type => Boolean, :default => true
end

Does it sound good? Hope this helps!

ShogunPanda
  • 1,046
  • 1
  • 10
  • 11
6

I had to put in my User model:

has_many :friendships, :inverse_of => :owner

Check out associations in the documentation http://mongoid.org/en/mongoid/docs/relations.html#common

Kevin Bahr
  • 61
  • 1
  • 1