2011-08-21 59 views
3

我有这个关系Mongoid accepts_nested_attributes_for问题

class Bird 
    include Mongoid::Document 
    has_many :eggs 
    accepts_nested_attributes_for :eggs 
end 

class Egg 
    include Mongoid::Document 
    belongs_to :bird 
end 

bird = Bird.new 
#=> #<Bird... 
bird.eggs.build 
#=> #<Egg... 
bird.save 
bird.reload.eggs 
#=> [] 

哪里是我的鸡蛋!

回答

4

更改has_many

has_many :eggs, :autosave => true