Relation In Mongodb using mongoid

Hi All,
I am trying to implement follow and unfollow functionality like in
twitter in my application. I am new to mongodb and I am using mongoid in
my rails 3 app. I dont know how to make a relation between my User model
and friends model. And I am also maintaining a model named deals which
contains the user_id as a forign key and I also want to display the
latest deals post by user that have been followed by me. Anyone please
guide me to implement this functionality.
Thanks a lot in Advance…

Mohammed N. wrote in post #995052:

Hi All,
I am trying to implement follow and unfollow functionality like in
twitter in my application. I am new to mongodb and I am using mongoid in
my rails 3 app. I dont know how to make a relation between my User model
and friends model. And I am also maintaining a model named deals which
contains the user_id as a forign key and I also want to display the
latest deals post by user that have been followed by me. Anyone please
guide me to implement this functionality.
Thanks a lot in Advance…

All this is explained in the Mongoid documentation:

http://mongoid.org/docs/relations.html

MongoDB isn’t a relational database, which means there are differences
in how models are associated. First you need to decide which type of
association is best for a given relationship. Do you want the associated
objects to be “embedded” in the document, or do you want to store
references in the document.

http://mongoid.org/docs/relations/embedded.html
http://mongoid.org/docs/relations/referenced.html

Using embedded relations you can choose from one-to-many or one-to-one.
If you need many-to-many then you’ll need to use referenced.

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