{"record":{"id":"284f511f2e75fede","repo":"mongodb/mongoid","slug":"attempted-to-modify-the-read-only-association-n","errorCode":null,"errorMessage":"Attempted to modify the read-only association '%{name}' on '%{klass}'.","messagePattern":"Attempted to modify the read-only association '%(.+?)' on '%(.+?)'\\.","errorType":"exception","errorClass":"Mongoid::Errors::ReadonlyAssociation","httpStatus":null,"severity":"error","filePath":"lib/mongoid/association/referenced/has_many_through.rb","lineNumber":191,"sourceCode":"            if reload || !instance_variable_defined?(\"@_#{assoc_name}\")\n              set_relation(assoc_name, HasManyThrough::Proxy.new(self, assoc))\n            end\n            instance_variable_get(\"@_#{assoc_name}\")\n          end\n        end\n\n        def define_through_ids_getter!\n          assoc_name = name\n          ids_method = :\"#{assoc_name.to_s.singularize}_ids\"\n          @owner_class.re_define_method(ids_method) do\n            send(assoc_name).pluck(:_id)\n          end\n        end\n\n        def define_readonly_setter!\n          assoc = self\n          @owner_class.re_define_method(:\"#{name}=\") do |_object|\n            raise Mongoid::Errors::ReadonlyAssociation.new(self.class, assoc)\n          end\n        end\n\n        def default_primary_key\n          PRIMARY_KEY_DEFAULT\n        end\n      end\n    end\n  end\nend\n","sourceCodeStart":173,"sourceCodeEnd":202,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/association/referenced/has_many_through.rb#L173-L202","documentation":"Error \"Attempted to modify the read-only association '%{name}' on '%{klass}'.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/association/referenced/has_many_through.rb:191 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"}