-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
class Test1 include Mongoid::Document embeds_one :test2, :store_as => :t field :name end class Test2 include Mongoid::Document embedded_in :test1 field :name end t = Test1.new(:name => "hi") t.build_test2(:name => "there") t.save # Will throw an error t.dup() # Mongoid::Errors::UnknownAttribute: # Problem: # Attempted to set a value for 't' which is not allowed on the model Test1. # Summary: # Without including Mongoid::Attributes::Dynamic in your model and the attribute does not already exist in the attributes hash, attempting to call Test1#t= for it is not allowed. This is also triggered by passing the attribute to any method that accepts an attributes hash, and is raised instead of getting a NoMethodError. # Resolution: # You can include Mongoid::Attributes::Dynamic if you expect to be writing values for undefined fields often.