我有:
class Foo
include Mongoid::Document
field :year, :type => Integer, :default => Time.now.utc.year
field :month, :type => Integer, :default => Time.now.utc.month
field :day, :type => Integer, :default => Time.now.utc.day
validates :day, :uniqueness => { :scope => [:month,:year] }
end
我做了以下两次:
Foo.create(:day => 24, :year => 2013, :month => 5)
我没有得到验证错误。相反,我有两个相同的记录。我做错了什么?
答案 0 :(得分:0)
试
validates_uniqueness_of :day, scope: [:month,:year]