{"record":{"id":"7af3786e0dc9b54c","repo":"mongodb/mongoid","slug":"attempted-to-save-document-before-the-parent","errorCode":null,"errorMessage":"Attempted to save %{document} before the parent %{base}.","messagePattern":"Attempted to save %(.+?) before the parent %(.+?)\\.","errorType":"exception","errorClass":"Mongoid::Errors::UnsavedDocument","httpStatus":null,"severity":"error","filePath":"lib/mongoid/association/proxy.rb","lineNumber":165,"sourceCode":"      # @example Raise the error.\n      #   relation.raise_mixed\n      #\n      # @raise [ Errors::MixedRelations ] The error.\n      def raise_mixed\n        raise Errors::MixedRelations.new(_base.class, _association.klass)\n      end\n\n      # When the base is not yet saved and the user calls create or create!\n      # on the association, this error will get raised.\n      #\n      # @example Raise the error.\n      #   relation.raise_unsaved(post)\n      #\n      # @param [ Document ] doc The child document getting created.\n      #\n      # @raise [ Errors::UnsavedDocument ] The error.\n      def raise_unsaved(doc)\n        raise Errors::UnsavedDocument.new(_base, doc)\n      end\n\n      # Executes a callback method\n      #\n      # @example execute the before add callback\n      #   execute_callback(:before_add)\n      #\n      # @param [ Symbol ] callback to be executed\n      def execute_callback(callback, doc)\n        _association.get_callbacks(callback).each do |c|\n          if c.is_a? Proc\n            c.call(_base, doc)\n          else\n            _base.send c, doc\n          end\n        end\n      end\n","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/association/proxy.rb#L147-L183","documentation":"Error \"Attempted to save %{document} before the parent %{base}.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/association/proxy.rb:165 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"}