0
感謝您的時間!mongoid embeds_one build howto
代碼很簡單(無軌使用mongoid):
require 'mongoid' # version 6.0.2
Mongoid.load!('mongoid.yml', :development)
class Office
include Mongoid::Document
embeds_one :owner
embeds_many :addresses
end
class Owner
include Mongoid::Document
end
class Address
include Mongoid::Document
end
我可以成功調用office.addresses.build
如下。
office = Office.new
office.addresses.build
office.save
但是,當我打電話office.owner.build
,錯誤彈出說
embed_one.rb:23:in `<main>': undefined method `build' for nil:NilClass (NoMethodError)
它應該以這種方式工作的,對不對?哪裏錯了。
puts office.owner.class # NilClass