{"record":{"id":"dcbae3df1b71517f","repo":"mongodb/mongoid","slug":"attributes-for-nested-association-association-n","errorCode":null,"errorMessage":"Attributes for nested association '#{association.name}' must be a Hash or an Array of key/value pairs.","messagePattern":"Attributes for nested association '#(.+?)' must be a Hash or an Array of key/value pairs\\.","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/mongoid/association/nested/many.rb","lineNumber":40,"sourceCode":"        #   many.build(person)\n        #\n        # @param [ Document ] parent The parent document of the association.\n        # @param [ Hash ] options The options.\n        #\n        # @return [ Array ] The attributes.\n        def build(parent, options = {})\n          @existing = parent.send(association.name)\n          raise Errors::TooManyNestedAttributeRecords.new(existing, options[:limit]) if over_limit?(attributes)\n\n          attributes.each do |attrs|\n            if attrs.is_a?(::Hash)\n              process_attributes(parent, attrs.with_indifferent_access)\n            elsif attrs.is_a?(Array) && attrs.length > 1 && attrs[1].respond_to?(:with_indifferent_access)\n              process_attributes(parent, attrs[1].with_indifferent_access)\n            elsif attrs.is_a?(Array) && attrs.length.even?\n              process_attributes(parent, Hash[*attrs].with_indifferent_access)\n            else\n              raise ArgumentError,\n                    \"Attributes for nested association '#{association.name}' must be a Hash or an Array of key/value pairs.\"\n            end\n          end\n        end\n\n        # Create the new builder for nested attributes on one-to-many\n        # associations.\n        #\n        # @example Initialize the builder.\n        #   Many.new(association, attributes, options)\n        #\n        # @param [ Mongoid::Association::Relatable ] association The association metadata.\n        # @param [ Hash ] attributes The attributes hash to attempt to set.\n        # @param [ Hash ] options The options defined.\n        def initialize(association, attributes, options = {})\n          @attributes = if attributes.respond_to?(:with_indifferent_access)\n                          attributes.with_indifferent_access.sort do |a, b|\n                            a[0].to_i <=> b[0].to_i","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/association/nested/many.rb#L22-L58","documentation":"Error \"Attributes for nested association '#{association.name}' must be a Hash or an Array of key/value pairs.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/association/nested/many.rb:40 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"}