我有这种关系
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
#=> []
我的鸡蛋在哪里!
答案 0 :(得分:4)
将has_many
更改为
has_many :eggs, :autosave => true