Provides ActiveRecord support for the nonstandard
SET data types.
It sucks to have ActiveRecord not understand your
ENUM columns and constantly write the wrong thing to your
It also sucks to work with a database that uses
ENUM in production when you'd prefer sqlite in development.
Wait no longer...
create_table :balloons, :force => true do |t| t.enum "color", :limit => ['red', 'gold'], :default => 'gold', :null => false # or... t.column "size", :enum, :limit => ['small', 'medium', 'large'] end
Your schema<->db coupling will work again, and it will fall back to a
VARCHAR column on any adapters that don't support
Boy, that was easy.
It currently works with:
- Rails 3.0, 3.1, 3.2, 4.0.
- Ruby 1.9.3, 2.0.0. It probably also works with Ruby 1.8, but that is unsupported.
If you'd like to support other adapters, pull requests are welcome!
Following ActiveRecord's lead, this plugin doesn't do any validation work itself.
For ENUM columns, you may be satisfied with something simple:
validates_inclusion_of :attr, :in => [ :possible, :values ]
Or if you prefer more bells and whistles, try nofxx/symbolize.
For SET columns, you may be interested in iangreenleaf/active_set.
This isn't a plugin everyone should use. There are a number of plugins to simulate enum behavior backed by standard data types. Personally, I like nofxx/symbolize.
However, sometimes we can't or won't avoid working with these data types. When that happens, I got you covered.
Pull requests welcome! Join this lovely bunch of people.
To run the tests for all supported database adapters:
To run the tests for all adapters and all versions of ActiveRecord:
To run the tests for just one adapter:
DB=mysql rake spec