Skip to content

Instantly share code, notes, and snippets.

@kklimuk
Created April 3, 2017 04:51
Show Gist options
  • Save kklimuk/ab3cf0ac9539697b6e7c022726f7f8b7 to your computer and use it in GitHub Desktop.
Save kklimuk/ab3cf0ac9539697b6e7c022726f7f8b7 to your computer and use it in GitHub Desktop.
def users_with_discounts(scoped_to={})
@users_with_discounts ||= {}
return @users_with_discounts[scoped_to] if @users_with_discounts.has_key?(scoped_to)
users = User.includes(payment_plan: :discounts).where(
paying: true,
**scoped_to
).to_a
@users_with_discounts[scoped_to] = users.select do |users|
users.payment_plan.discounts.any? && !users.payment_plan.delayed?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment