我有:
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)
我没有收到验证错误。相反,我有两条相同的记录。我究竟做错了什么?