【问题标题】:Mongoid accepts_nested_attributes_for issueMongoid 接受_nested_attributes_for 问题
【发布时间】:2023-03-25 15:25:01
【问题描述】:

我有这种关系

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

我的蛋呢!

【问题讨论】:

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


    【解决方案1】:

    has_many 更改为

    has_many :eggs, :autosave => true
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-04
      • 2011-01-13
      相关资源
      最近更新 更多