Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 389 Bytes

rb_rails_activerecord_enums.md

File metadata and controls

23 lines (17 loc) · 389 Bytes

Enums werden in der Migration und der Datenbank als Integer definiert.

Im Model definiert man die Werte dann so:

enum company_type: %i[mine candidate external other]

{enum}_before_type_cast:

c = Company.find_by(company_type: 'mine')
c.company_type_before_type_cast
=> 0

{record}.{enum_value}?:

c = Company.find_by(company_type: 'mine')
c.mine?
=> true