Skip to content

Instantly share code, notes, and snippets.

@bogdan
Created January 2, 2018 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bogdan/3a06bfc1ab6eda0ea5a10c47579baec3 to your computer and use it in GitHub Desktop.
Save bogdan/3a06bfc1ab6eda0ea5a10c47579baec3 to your computer and use it in GitHub Desktop.
where(person_id: Person.find_by(email: email, site_id: site_id), site_id: site_id)
}
+ scope :by_coupon_list, ->(coupon_list_id) {
+ sub_query = Coupon.
+ joins('INNER JOIN `checkout_coupons` ON `checkout_coupons`.`coupon_id` = `coupons`.`id`').
+ where('`origins`.`id` = `checkout_coupons`.`purchase_id`').where(coupon_list_id: coupon_list_id)
+ where("exists (#{sub_query.to_sql})")
+ }
+
scope :with_mobile_visitor, ->(mobile) {
return if mobile.nil?
joins(:visitor).merge(Visitor.mobile(mobile))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment