{"record":{"id":"ca3488db7ab8358f","repo":"activerecord-hackery/ransack","slug":"type-cannot-be-converted-to-an-arel-join-type","errorCode":null,"errorMessage":"#{type} cannot be converted to an ARel join type","messagePattern":"#(.+?) cannot be converted to an ARel join type","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/polyamorous/join.rb","lineNumber":51,"sourceCode":"    alias :== :eql?\n\n    def add_to_tree(hash)\n      hash[self] ||= {}\n    end\n\n    private\n\n    def convert_to_arel_join_type(type)\n      case type\n      when 'inner', :inner\n        InnerJoin\n      when 'outer', :outer\n        OuterJoin\n      when Class\n        if [InnerJoin, OuterJoin].include? type\n          type\n        else\n          raise ArgumentError, \"#{type} cannot be converted to an ARel join type\"\n        end\n      else\n        raise ArgumentError, \"#{type} cannot be converted to an ARel join type\"\n      end\n    end\n\n    def convert_to_class(value)\n      case value\n      when String, Symbol\n        Kernel.const_get(value)\n      when Class\n        value\n      else\n        raise ArgumentError, \"#{value} cannot be converted to a Class\"\n      end\n    end\n\n  end","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/activerecord-hackery/ransack/blob/e82f6bab3956c5597e7debbefa218d9e94e58ceb/lib/polyamorous/join.rb#L33-L69","documentation":"Polyamorous (Ransack's join-handling subsystem) raises this ArgumentError when a join type is given as a Class that is not one of the two accepted Arel join node classes (Polyamorous::InnerJoin / Polyamorous::OuterJoin). The join type for Polyamorous::Join must be 'inner'/:inner, 'outer'/:outer, or one of those exact classes. Any other Class (for example a raw Arel::Nodes::InnerJoin or a custom join class) is rejected by convert_to_arel_join_type.","triggerScenarios":"Polyamorous::Join.new(:articles, SomeJoinClass) or Polyamorous::Join#type=(SomeJoinClass) where SomeJoinClass is not Polyamorous::InnerJoin/OuterJoin. Typical case: passing Arel::Nodes::InnerJoin (the Arel node class itself) instead of the Polyamorous alias, or a custom join class from code written against an older Polyamorous API.","commonSituations":"Upgrading Ransack/Polyamorous after the join-type API was narrowed to the two Arel node classes; copy-pasted custom join code from old blog posts that passes Arel node classes; monkey-patches or custom adapters that build Join objects with their own join class hierarchy.","solutions":["Pass one of the accepted values: :inner, :outer, 'inner', or 'outer' — e.g. Polyamorous::Join.new(:articles, :outer)","If you need the class form, use Polyamorous::InnerJoin or Polyamorous::OuterJoin exactly — they are the only whitelisted classes","If you were passing Arel::Nodes::InnerJoin/Arel::Nodes::OuterJoin, replace them with the Polyamorous constants (which alias the correct nodes for your Rails version)","Remove custom join classes and express the join via Ransack's normal association-name + join_type API"],"exampleFix":"# before\njoin = Polyamorous::Join.new(:articles, Arel::Nodes::InnerJoin)\n# => ArgumentError: Arel::Nodes::InnerJoin cannot be converted to an ARel join type\n\n# after\njoin = Polyamorous::Join.new(:articles, Polyamorous::InnerJoin)\n# or simply\njoin = Polyamorous::Join.new(:articles, :inner)","handlingStrategy":"validation","validationCode":"VALID_JOIN_TYPES = [Polyamorous::InnerJoin, Polyamorous::OuterJoin].freeze\n\ndef valid_join_type?(type)\n  %w[inner outer].include?(type.to_s) || VALID_JOIN_TYPES.include?(type)\nend\n\n# before constructing:\nraise ArgumentError, \"bad join type: #{type}\" unless valid_join_type?(type)\njoin = Polyamorous::Join.new(:articles, type)","typeGuard":"def polyamorous_join_type?(type)\n  case type\n  when 'inner', :inner, 'outer', :outer then true\n  when Class then [Polyamorous::InnerJoin, Polyamorous::OuterJoin].include?(type)\n  else false\n  end\nend","tryCatchPattern":"begin\n  join = Polyamorous::Join.new(:articles, type)\nrescue ArgumentError => e\n  Rails.logger.warn(\"Falling back to inner join: #{e.message}\")\n  join = Polyamorous::Join.new(:articles, :inner)\nend","preventionTips":["Standardize on the symbols :inner/:outer everywhere in your codebase; never pass raw Arel node classes","If join types come from config or params, whitelist them against %w[inner outer] before use","Add a spec asserting your custom join-building code only emits the two accepted values"],"tags":["ruby","rails","ransack","polyamorous","activerecord","joins","argumenterror"],"backgroundTag":"invalid-argument-type","analyzedSha":"e82f6bab3956c5597e7debbefa218d9e94e58ceb","analyzedAt":"2026-08-21T19:30:23.639Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}