Reputation: 376
is this the correct way to declare an attribute as an enum?
enum condition: [:recent, :overhaul, :as_removed, :serviceable, :non_serviceable, :scrap]
Or should it be?
enum condition: {recent: 0, overhaul: 1, as_removed: 2, serviceable: 3, non_serviceable: 4, scrap: 5}
The first option has been working fine, but now I'm running into issues writing tests, using Factory Girl.
Upvotes: 0
Views: 353
Reputation: 496
Both options are correct declarations of enum. The second one explicitly map the relation between attribute and database integer. But in the examples posted by you the final result would be exactly the same.
You can find a detailed documentation of the Enum
module in Ruby on Rails API documentation.
Upvotes: 1