Reputation: 620
validates_uniqueness_of :prod_id, :scope => [:col_id, :parent_col_id], :conditions => lambda { |table| table[:state].not_in(%w(cancelled denied)) }
I can't find any documentation for passing :conditions to validates_uniqueness_of... I'm looking for an explanation.
Update - thanks for the answer, a custom validation or using if or less would make sense... however this is pre-existing code that I'm trying to fully understand before changing.
Upvotes: 1
Views: 861
Reputation: 541
You can make your own validation method for this. For example:
validates_uniqueness_of :prod_id, :scope => [:col_id, :parent_col_id],
:if => :custom_validation
def custom_validation
#your code here
end
Upvotes: 4