I’m trying to represent a relationship between users in my application where a user can have many followers and can follow other users.
I would like to have something like user.followers() and user.followed_by()
Could you please tell me in details how to represent this using ActiveRecord?
Thanks.
You need two models, a Person and a Followings
and the following code in the models
and corresponding in the Followings class you write
You could make the names clearer to your liking (i especially don’t like the
Followings-name), but this should get you started.