为什么验证不起作用embeds_one
?
class Foo
include Mongoid::Document
embeds_one :bar, :cascade_callbacks => true
end
class Bar
include Mongoid::Document
embedded_in :foo
field :test, :type => String
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 :year, :uniqueness => true, :presence => true, :scope => [:month, :day]
# validates :day, :uniqueness => { :scope => [:month,:year] }
validates_uniqueness_of :year, :scope => :day
end
Foo.create(:bar => { :test => 'asdf' }) # created document
Foo.create(:bar => { :test => 'asdf' }) # created document, no validation thrown!
为什么 Foo 被多次创建?