0
爲什麼不驗證使用embeds_one
?爲什麼不使用`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被多次創建?