Rails numbering: String column or Integer?

I am currently looking for a suitable Rails stone for listings.

I have already tried

  • enum_simulator
  • has_enum

    • Both use a row column in the database to store enumeration data. Wouldn't an integer column have better performance or less memory consumption (using MySQL)?
    • Is there a stone that can already do this?

Thanks a lot!

Update: I found a simple_enum pearl that uses integer values ​​to represent an enumeration in a database. It supports rails 3.1 and is well supported.

+4
source share
2 answers

Ruby Toolbox is your friend. https://www.ruby-toolbox.com/categories/Active_Record_Enumerations

I used enumerated_attribute with both Rails 2.3 and Rails 3 with good results. Yes, it uses a string column.

IMO column strings are better than whole columns because they do not imply any order of values ​​and make it easier to understand an attribute (reverse engineer if you want) without looking at the source code. And usually the performance difference is small, especially if you have an index in the field - and you should.

Using the MySQL enum field turned out to be difficult in Rails 2.3, the problem with the schemas is not sure if it is saved in Rails 3.

+4
source

Look for this stone: enumerate_it . I think this solves your problem!

0
source

All Articles