class User
has_many :books
I need a query that returns:
Users whose most recent book has :complete => true. i.e. If a user's most recent book has :complete => false, I do not want them in my result.
What I have so far
User.joins(:books).merge(Book.where(:complete => true))
which is a promising start but does not give me the result I need. I've tried adding an .order("created_on desc").limit(1)
to the end of the above query but then I end up with only one result when I am expecting many.
Thanks!
See Question&Answers more detail:os