I want to return Users with Books which are part of a scope -
class User < ActiveRecord::Base
has_many :books
end
class Book < ActiveRecord::Base
belongs_to :user
scope :published, -> { where (status: 'Published') }
end
So
Book.published
returns all the published books. I'm trying to define a scope of all users who have one or more published books.
Knowing that
User.joins(:books).uniq.all
returns all users with a book (from Rails: How to get objects with at least one child?) - can I add a scope to that, or is there a better approach?