Skip to content

Instantly share code, notes, and snippets.

@DriesS
Created August 17, 2012 12:31
Show Gist options
  • Save DriesS/3378473 to your computer and use it in GitHub Desktop.
Save DriesS/3378473 to your computer and use it in GitHub Desktop.
Name scope use self.id
class Discount < ActiveRecord::Base
scope :unused, lambda {|user| {:conditions => ["(select count(orders.id) from orders where discount_id = ? AND state IN ('shipped', 'paid', 'completed', 'processing') AND orders.user_id = ?)=0", self.id, user.id]}}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment