Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for enums in Rails 7 #227

Open
jwg2s opened this issue Jul 14, 2023 · 0 comments
Open

Support for enums in Rails 7 #227

jwg2s opened this issue Jul 14, 2023 · 0 comments

Comments

@jwg2s
Copy link

jwg2s commented Jul 14, 2023

This tripped us up trying to upgrade to Rails 7, where the enum_types were duplicated by however many schemas you had. The following monkey patch will get you past it, at least until you figure out how to stop using apartment entirely!

Values Returned Before

create_enum "status", ["not_started", "not_started", "not_started", "in_progress", "in_progress", "in_progress", "complete", "complete", "complete"]

Monkeypatch

module ActiveRecord
  class Base
    class << self
      def connection_with_enum_types_patch
        patched_connection = connection_without_enum_types_patch

        def patched_connection.enum_types
          super.map do |name, value|
            [name, value.split(",").uniq.join(",")]
          end
        end

        patched_connection
      end

      alias_method :connection_without_enum_types_patch, :connection
      alias_method :connection, :connection_with_enum_types_patch
    end
  end
end

Values Returned After

create_enum "status", ["not_started", "in_progress", "complete"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant