electronick / enum_column

Enum column support for Rails 3
MIT License
75 stars 45 forks source link

This is incompatible with rails 4.2 #25

Open harsimranmaan opened 9 years ago

harsimranmaan commented 9 years ago

enum_column3-0.1.4/lib/enum/enum_adapter.rb:30:in block in <top (required)>': undefined methodtype_cast' for class `ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::Column' (NameError)

trivektor commented 9 years ago

It looks like this issue has been fixed on master but the update has not been released to rubygems.org yet. You can just point to the source in your Gemfile and install it to get the fix.

Lambenttelos commented 9 years ago

I am having trouble on rails 4.2 still. A fix I found would be to move the alias lines below the methods they are aliasing in enum_adapter.rb.

schuylr commented 9 years ago

@Lambenttelos This doesn't work. By moving the aliasing after the override definitions, you're just aliasing the newly declared methods. Your columns will have a type of :string and you'll get a string instead of symbols. This is a silent failure.

The break in Rails 4.2 is because of this refactoring and other subsequent updates by @sgrif - instead of defining the type using simplified_type, it's now set up in ActiveRecord::ConnectionAdapters::Mysql2Adapter using initialize_type_map. You also have to declare a new ActiveRecord::Type::Enum class to convert the values to and from the database, and return a proper :enum type for ActiveRecord to handle.

I've made all of these changes in https://github.com/jewlr/enum_column for those who are interested. The code should also be backwards compatible down to Rails 3.

Lambenttelos commented 9 years ago

@schuylr Thanks for the update! I just took a novice guess at it and yeah that one change I suggested would have just changed where I would have run into errors then. With the project I was updating at the time we just decided to rip out the gem and use the built in enum functionality that is in active record now which was easy for us as our use case was simple. We have some other projects that are not so simple and this fix should save some headaches.