{"record":{"id":"4b926688c972a44c","repo":"mongodb/mongoid","slug":"could-not-find-metadata-for-association-name","errorCode":null,"errorMessage":"Could not find metadata for association '%{name}' on model: %{klass}.","messagePattern":"Could not find metadata for association '%(.+?)' on model: %(.+?)\\.","errorType":"exception","errorClass":"Mongoid::Errors::NestedAttributesMetadataNotFound","httpStatus":null,"severity":"error","filePath":"lib/mongoid/attributes/nested.rb","lineNumber":54,"sourceCode":"        #\n        # @option *args [ true | false ] :allow_destroy Can deletion occur?\n        # @option *args [ Proc | Symbol ] :reject_if Block or symbol pointing\n        #   to a class method to reject documents with.\n        # @option *args [ Integer ] :limit The max number to create.\n        # @option *args [ true | false ] :update_only Only update existing docs.\n        # @option *args [ true | false ] :autosave Whether autosave should be enabled on the\n        #   association. Note that since the default is true, setting autosave to nil will still\n        #   enable it.\n        def accepts_nested_attributes_for(*args)\n          options = args.extract_options!.dup\n          options[:autosave] = true if options[:autosave].nil?\n\n          options[:reject_if] = REJECT_ALL_BLANK_PROC if options[:reject_if] == :all_blank\n          args.each do |name|\n            meth = \"#{name}_attributes=\"\n            nested_attributes[\"#{name}_attributes\"] = meth\n            association = relations[name.to_s]\n            raise Errors::NestedAttributesMetadataNotFound.new(self, name) unless association\n\n            autosave_nested_attributes(association) if options[:autosave]\n\n            re_define_method(meth) do |attrs|\n              _assigning do\n                if association.polymorphic? and association.inverse_type\n                  klass = association.resolver.model_for(send(association.inverse_type))\n                  options = options.merge!(class_name: klass)\n                end\n                association.nested_builder(attrs, options).build(self)\n              end\n            end\n          end\n        end\n\n        private\n\n        # Add the autosave information for the nested association.","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/attributes/nested.rb#L36-L72","documentation":"Error \"Could not find metadata for association '%{name}' on model: %{klass}.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/attributes/nested.rb:54 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"}