I have this method which returns all the categories and groups books belonging to that category
def self.user_categories_list
joins(:books).
select('categories.id, categories.name, count(*) AS books_count').
group('categories.id, categories.name').
order('books_count DESC')
end
Please excuse my question but I am unsure on how to join the users table to get all books belonging to a user by category, or could i do it by book_id belonging to a user?
Any help appreciated
Thanks
I think you should just had a where clause:
Note: This code assumes that your Book model has the
user_idattribute in its table.