{"record":{"id":"e517c6d01138c7c5","repo":"mongodb/mongoid","slug":"cannot-persist-embedded-document-klass-without","errorCode":null,"errorMessage":"Cannot persist embedded document %{klass} without a parent document.","messagePattern":"Cannot persist embedded document %(.+?) without a parent document\\.","errorType":"exception","errorClass":"Mongoid::Errors::NoParent","httpStatus":null,"severity":"error","filePath":"lib/mongoid/persistable/creatable.rb","lineNumber":57,"sourceCode":"        { atomic_insert_modifier => { atomic_position => as_attributes } }\n      end\n\n      # Insert the embedded document.\n      #\n      # When the parent association is touchable (which is the default for\n      # +embedded_in+), the touch timestamp updates are merged into the\n      # same +update_one+ call that performs the insert. This avoids a\n      # second round-trip that the +after_save+ touch callback would\n      # otherwise issue.\n      #\n      # @api private\n      #\n      # @example Insert the document as embedded.\n      #   document.insert_as_embedded\n      #\n      # @return [ Document ] The document.\n      def insert_as_embedded\n        raise Errors::NoParent.new(self.class.name) unless _parent\n\n        if _parent.new_record?\n          _parent.insert\n        else\n          selector = _parent.atomic_selector\n          operations = atomic_inserts\n\n          if _touchable_parent?\n            touches = _parent._gather_touch_updates(Time.current)\n            if touches.present?\n              operations['$set'] = (operations['$set'] || {}).merge(touches)\n              Threaded.begin_touch_merged(self)\n            end\n          end\n\n          _root.collection.find(selector).update_one(\n            positionally(selector, operations),\n            session: _session","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/persistable/creatable.rb#L39-L75","documentation":"Error \"Cannot persist embedded document %{klass} without a parent document.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/persistable/creatable.rb:57 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0da0e23d71adfbad31128c18e5e2c8c301c6f7c4","analyzedAt":"2026-08-23T06:25:47.656Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}