{"record":{"id":"9aa00d35029f345d","repo":"theforeman/foreman","slug":"could-not-find-association-with-name-name","errorCode":null,"errorMessage":"Could not find %{association} with name: %{name}","messagePattern":"Could not find %(.+?) with name: %(.+?)","errorType":"validation","errorClass":"Foreman::AssociationNotFound","httpStatus":null,"severity":"error","filePath":"app/models/concerns/has_many_common.rb","lineNumber":86,"sourceCode":"        send(association).map(&:name_method)\n      end\n    end\n\n    #### belongs_to ####\n    def belongs_to(name, scope = nil, name_accessor: nil, **kwargs)\n      belongs_to_name_for(name, name_accessor)\n      super(name, scope, **kwargs)\n    end\n\n    def belongs_to_name_for(association, name_accessor)\n      assoc = association.to_s.tableize.singularize\n      assoc_name = name_accessor || \"#{assoc}_name\"\n\n      # SETTER _name= method\n      define_method \"#{assoc_name}=\" do |name_value|\n        assoc_id = assoc_klass(association).send(\"find_by_#{assoc_klass(association).attribute_name}\", name_value).try(:id)\n        unless assoc_id\n          raise Foreman::AssociationNotFound\n                  .new(_(\"Could not find %{association} with name: %{name}\") % { name: name_value, association: association })\n        end\n        send(\"#{assoc}_id=\", assoc_id)\n      end\n\n      # GETTER _name method\n      define_method assoc_name do\n        send(association).try(:name_method)\n      end\n    end\n  end\nend\n","sourceCodeStart":68,"sourceCodeEnd":99,"githubUrl":"https://github.com/theforeman/foreman/blob/6b05625475cfe6aac31a88f8c8ee6e62e4efe620/app/models/concerns/has_many_common.rb#L68-L99","documentation":"Error \"Could not find %{association} with name: %{name}\" thrown in theforeman/foreman.","triggerScenarios":"Thrown at app/models/concerns/has_many_common.rb:86 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":"6b05625475cfe6aac31a88f8c8ee6e62e4efe620","analyzedAt":"2026-08-23T17:46:34.094Z","schemaVersion":2},"datasetVersion":"2026-08-23T21:17:23.414Z"}