Post
s belong to User
s. User
s have and belong to many roles (i.e., the tables we're dealing with here are posts
, users
, roles
, and roles_users
)
How can I select all posts written by a user who has the "Editor" role?
I.e., I want the database-driven version of
Post.all.select{|p| p.user.roles.map(&:name).include?("Editor")}}