fl00r
fl00r

Reputation: 83680

Mongoid accepts_nested_attributes_for issue

I have got this relations

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

Where are my eggs!

Upvotes: 3

Views: 752

Answers (1)

rubish
rubish

Reputation: 10907

Change the has_many to

has_many :eggs, :autosave => true

Upvotes: 4

Related Questions