thetron / mongoid-enum

Sweet enum sugar for your Mongoid documents
MIT License
117 stars 166 forks source link

Mongoid 7.0 and 7.2 support #55

Open muhammetfaik opened 5 years ago

muhammetfaik commented 5 years ago

Help !!!

base) ➜  raceday git:(master) ✗ bundle
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Bundler could not find compatible versions for gem "mongoid":
  In snapshot (Gemfile.lock):
    mongoid (= 7.0.2)

  In Gemfile:
    mongoid (~> 7.0, >= 7.0.2)

    mongoid_enum was resolved to 1.1.0, which depends on
      mongoid (~> 5.0)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.
wangaguo commented 4 years ago

Hi, Can you help to support new version mongoid.

choilive commented 3 years ago

gem "mongoid-enum", :git => 'https://github.com/choilive/mongoid-enum.git'

I have updated it to support mongoid 7, looks like the maintainer is inactive for this project

TimoPurzner commented 3 years ago

@choilive pretty cool but I get errors if I try to install it I got ruby 3.0.0

current directory: ...../.rvm/gems/ruby-3.0.0/gems/bigdecimal-1.4.4/ext/bigdecimal
make "DESTDIR="
compiling bigdecimal.c
bigdecimal.c:421:5: error: implicit declaration of function 'rb_check_safe_obj' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    rb_check_safe_obj(str);
    ^
bigdecimal.c:421:5: note: did you mean 'rb_check_safe_str'?
/Users/timopurzner/.rvm/rubies/ruby-3.0.0/include/ruby-3.0.0/ruby/internal/core/rstring.h:97:6: note: 'rb_check_safe_str' declared here
void rb_check_safe_str(VALUE);
     ^
bigdecimal.c:2030:6: error: implicit declaration of function 'rb_check_safe_obj' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
            rb_check_safe_obj(f);
            ^
2 errors generated.
make: *** [bigdecimal.o] Error 1
choilive commented 3 years ago

@ZeroSoulEater hm yes, this gem depends on bigdecimal 1.4.x which is not compatible with ruby 3, I'll try upgrading bigdecimal 2.0 and see if it still works.

jramiresbrito commented 3 years ago

gem "mongoid-enum", :git => 'https://github.com/choilive/mongoid-enum.git'

I have updated it to support mongoid 7, looks like the maintainer is inactive for this project

Hey @choilive, thanks for update it!

I'm having problems on use the enum.

Basically my model have this field called type, like that:

field :type, type: Integer

Which will be a enum: enum type: { type_1: 0, type_2: 1, type_3: 2 }

But i'm facing this error when I try to make a request passing type: "type_1":

"exception": "#<ArgumentError: wrong number of arguments (given 1, expected 2..3)>",

Any idea?

choilive commented 3 years ago

@jramiresbrito hey! it looks like you are trying to use enums in the style of ActiveRecord Enums, I dont think you can explicitly map between the attribute and the value in the same way here. The mongoid-enum gem does not try to be the same api as activerecord enum (it also came way before that was released)

something like enum :type, [:type_1, :type_2, :type_3] should work

avijit-sharma commented 2 years ago

@ZeroSoulEater hm yes, this gem depends on bigdecimal 1.4.x which is not compatible with ruby 3, I'll try upgrading bigdecimal 2.0 and see if it still works.

hey , is this working for ruby 3 ?,still showng error for me

Vector54 commented 1 year ago

@choilive Hey friend! It's been some time now. How's it working for MongoId 8?