Hi,
Is there a way to specify a default value for an embedded document or use hooks to mimic that behavior? For example, say I have these two classes:
class Foo
include Mongoid::Document
embeds_one :bar
end
class Bar
include Mongoid::Document
embedded_in :foo, :inverse_of => :bar
field :count, :type => Integer, :default => 0
end
Now I want to be able to do this:
f = Foo.new
f.bar.count # should return 0
Is there anyway to do this? It seems like something I could implement with a before_<somethingorother> hook but I can't seem to get it to work.
I'm on Mongoid 2.0.0.beta.20, Rails 3.0.4 and Ruby 1.9.2
Thanks in advance for your help.
Trevor