Activerecord Enums Tradeoffs

If you’re using Activerecord Enums, it’s common to store the values that represent the enums as integers in the database. If you wanted more guarantees from the database, you’d store the values as SQL enums. However, Rail’s schema dump doesn’t SQL enums very well.

Here are some tradeoffs:

Integers SQL enums
Database Guarantees No Yes
schema.rb Supported Not supported (need to use structure.sql)

Here’s a good tutorial on how to use Activerecord Enums for either case.

Comments are closed.

%d bloggers like this: