0

Using DataMapper Enum type for the first time, and I noticed the first value in the enum translates to a 1. I need this to be zero based to be backward compatiable with another ORM layer in a different application also reading this database.

Boiler Bill
  • 1,900
  • 1
  • 22
  • 32

1 Answers1

1

You should be able to monkey-patch enum.rb in dm-types to support this. You will need to replace the initialize method with a slightly modified copy where @flag_map[i+1] is replaced with @flag_map[i]:

module DataMapper
  class Property
    class Enum < Object

      def initialize(model, name, options = {})
        @flag_map = {}

        flags = options.fetch(:flags, self.class.flags)
        flags.each_with_index do |flag, i|
          @flag_map[i] = flag
        end

        if self.class.accepted_options.include?(:set) && !options.include?(:set)
          options[:set] = @flag_map.values_at(*@flag_map.keys.sort)
        end

        super
      end # end initialize

    end # end class Enum
  end # end class Property
end # end module DataMapper
Richard Fairhurst
  • 816
  • 1
  • 7
  • 15