Skip to content

Instantly share code, notes, and snippets.

@PerezIgnacio PerezIgnacio/users_query.rb Secret

Created Jan 31, 2020
Embed
What would you like to do?
Example of Query Object for User Model
class UsersQuery
attr_reader :relation
def initialize(relation = User.all)
@relation = relation
end
def subscribed
relation.where(receive_email_notifications: true)
end
def without_recent_views
relation.where('last_visited < ?', User::RECENT_VISITED_DAYS.days.ago)
end
def for_notifications_of_similar_purchases
relation.joins(:orders)
.where(fulfilled: true)
.and('orders.updated_at > ?', User::RECENT_ORDER_DAYS.days.ago)
.where(receive_email_notifications: true)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.