Created
August 17, 2012 12:31
-
-
Save DriesS/3378473 to your computer and use it in GitHub Desktop.
Name scope use self.id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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