2011-08-21 37 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