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

Closed
jwg2s opened this issue Jul 14, 2023 · 1 comment
Closed

Support for enums in Rails 7 #227

jwg2s opened this issue Jul 14, 2023 · 1 comment
Labels

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"]
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants