Ruby On Rails Lesson
The final piece of the relationships puzzle is to add a user.followers method to go with user.followed_users. You may have noticed from Figure 11.7 that all the information needed to extract an array of followers is already present in the relationships table. Indeed, the technique is exactly the same as for user following, with the roles of follower_id and followed_id reversed. This suggests that, if we could somehow arrange for a reverse_relationships table with those two columns reversed (Figure 11.9), we could implement user.followers with little effort.
We begin with the tests, having faith that the magic of Rails will come to the rescue (Listing 11.15).