I am struggling to achieve this
I have 3 models,
- User (has_many :posts)
- Post (Belongs_to :user, HABTM :categories)
- Category (HABTM :posts)
Now, let's say I want to find and order all users who have submitted most posts in a category, how do I achieve this.
Eg. For category 'Fashion' I want to fetch & order users by number of user's posts in fashion.
Desired result should give,
- Mark (7 posts in fashion)
- Dave (5 posts in fashion)
- Carla (4 posts in fashion) .. so on
Note: Would prefer a solution that is compatible with postgres