Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AR generalised association join, group, count, and filter
# app/models/concerns/exceeding.rb
module Exceeding
extend ActiveSupport::Concern
included do
scope :exceeds, ->(association, n) do
joins(association).group(primary_key).having(arel_table[primary_key].count.gteq n)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment