A social media app built with ruby on rails. It includes some of the core features of the facebook app which includes; users, friendships, posts, liking, comments, etc.
I didn't right away realize this but since for the past projects I've reviewed this has been happening. I was wondering if you can refactor the way you generate friendship records in the database:
ryto.friendships.create(friend_id: first.id) and then running Friendship.all shows:
I recognize that this is due to the create_mutual_friendship method you have in your Friendship model. However, doing it like this can easily fill up the database with unnecessary records. What we want is just to record a friendship once (and in fact enforcing uniqueness in the friendship between two users).
A way to do this is to keep track of which user adds the other. Similar to how you did it with FriendRequest (in here for every request made there is only one record generated).