So I've got a somewhat complicated architecture in a new microservice, and I'm having trouble figuring out how we can get this query done in Rails 6 ActiveRecord syntax, and not pulling the models into Ruby.
Find Authors where associated Posts' associated Comments are all status: 'moderated'
Authors have many Posts
Posts are Commentable (polymorphic join)
(Authors are also Commentable (polymorphic join))
Closest I can get is
Author.joins(posts: :comments)
.where.not(comments: { status: :needs_moderated })
.where(comments: { status: :moderated })
.group('authors.id')
Which gets me all Authors with posts, but I want Authors where ALL of their Posts' Comments are ONLY status: :moderated
Is this possible ?