Mongoid accepted_nested_attributes_for问题

时间:2011-08-21 16:39:38

标签: ruby-on-rails ruby mongodb mongoid ruby-on-rails-3.1

我有这种关系

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
#=> []

我的鸡蛋在哪里!

1 个答案:

答案 0 :(得分:4)

has_many更改为

has_many :eggs, :autosave => true