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
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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With