-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
I have mass assignment set to strict, and I have a model that embeds_many. When I save the model, Versioning creates a copy of the object. The copying of the top-level object is accomplished with "without_protection" set true, so that sanitize_for_mass_assignment() is used. However, once it gest to the process_relations method, that goes out the window. Subsequent objects are apparently not treated the same way. Therefore, ActiveModel::MassAssignmentSecurity::Error is thrown, complaining "Can't mass-assign protected attributes: metadata, _parent, _id, foo_association_id".
Here's the top part of my call stack:
activemodel (3.2.8) lib/active_model/mass_assignment_security/sanitizer.rb:48:in `process_removed_attributes' activemodel (3.2.8) lib/active_model/mass_assignment_security/sanitizer.rb:20:in `debug_protected_attribute_removal' activemodel (3.2.8) lib/active_model/mass_assignment_security/sanitizer.rb:12:in `sanitize' activemodel (3.2.8) lib/active_model/mass_assignment_security.rb:230:in `sanitize_for_mass_assignment' mongoid (3.0.6) lib/mongoid/attributes/processing.rb:24:in `process_attributes' mongoid (3.0.6) lib/mongoid/document.rb:148:in `block in initialize' mongoid (3.0.6) lib/mongoid/threaded/lifecycle.rb:84:in `_building' mongoid (3.0.6) lib/mongoid/document.rb:143:in `initialize' mongoid (3.0.6) lib/mongoid/factory.rb:23:in `new' mongoid (3.0.6) lib/mongoid/factory.rb:23:in `build' mongoid (3.0.6) lib/mongoid/relations/embedded/batchable.rb:197:in `block in normalize_docs' mongoid (3.0.6) lib/mongoid/relations/embedded/batchable.rb:194:in `map' mongoid (3.0.6) lib/mongoid/relations/embedded/batchable.rb:194:in `normalize_docs' mongoid (3.0.6) lib/mongoid/relations/embedded/batchable.rb:82:in `batch_replace' mongoid (3.0.6) lib/mongoid/relations/embedded/many.rb:277:in `substitute' mongoid (3.0.6) lib/mongoid/relations/accessors.rb:206:in `block (2 levels) in setter' mongoid (3.0.6) lib/mongoid/relations/accessors.rb:103:in `without_autobuild' mongoid (3.0.6) lib/mongoid/relations/accessors.rb:203:in `block in setter' mongoid (3.0.6) lib/mongoid/attributes/processing.rb:143:in `block in process_relations' mongoid (3.0.6) lib/mongoid/attributes/processing.rb:138:in `each_pair' mongoid (3.0.6) lib/mongoid/attributes/processing.rb:138:in `process_relations' mongoid (3.0.6) lib/mongoid/attributes/processing.rb:126:in `process_pending' mongoid (3.0.6) lib/mongoid/attributes/processing.rb:31:in `process_attributes' mongoid (3.0.6) lib/mongoid/document.rb:148:in `block in initialize' mongoid (3.0.6) lib/mongoid/threaded/lifecycle.rb:84:in `_building' mongoid (3.0.6) lib/mongoid/document.rb:143:in `initialize' mongoid (3.0.6) lib/mongoid/factory.rb:23:in `new' mongoid (3.0.6) lib/mongoid/factory.rb:23:in `build' mongoid (3.0.6) lib/mongoid/relations/embedded/many.rb:86:in `build' mongoid (3.0.6) lib/mongoid/versioning.rb:39:in `revise'