TIL #merge
is a thing on AR models.
Useful for joining + using a named scoped on the joined table:
class Post; end
class Comment; scope :approved, -> {approved: true}; end
Post.joins(:comments).merge(Comment.approved)
vs.
Post.joins(:comments).where(comments: {approved: true}) # this requires duplicating the logic defined in your scope