ruby on rails - Relationship like Twitter followers/followed in ActiveRecord -


I am trying to represent a connection between the users present in my application where the user can have many followers And other users can follow. I would like to do something like user.followers () and user.followed_by (). Can you please tell me in details how does it represent to use ActiveRecord?

Thank you.

You need two models, one person and follow up

  Rail Model Build Person's Name: String Rail Model produces person_itin: integer follower_id: integer blocking: boolean  

and the following code in the model

  class Person and lieutenant; ActiveRecord :: Base has_many: followers ,: class_name = & gt; 'Follow-up',: foreign_key = & gt; 'Person_id' has_many: Following,: class_name = & gt; 'Follow-up',: foreign_key = & gt; 'Follower_id' termination  

and consistent in the follow up class that you write

  class follow-up < ActiveRecord :: Base is_to: person belongs_to: follower, class_name = & gt; 'Person' end  

You can clear the name of your choice (I especially do not like the follow-up code) - but you should start this .


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -