Ruby on Rails
- 8 ответов
- 0 вопросов
2
Вклад в тег
class Conversation < ActiveRecord::Base
enum status: [ :active, :archived ]
end
# conversation.update! status: 0
conversation.active!
conversation.active? # => true
conversation.status # => "active"
# conversation.update! status: 1
conversation.archived!
conversation.archived? # => true
conversation.status # => "archived"
# conversation.update! status: 1
conversation.status = "archived"
# conversation.update! status: nil
conversation.status = nil
conversation.status.nil? # => true
conversation.status # => nil
#Автоскоупы модели для выборки по енум полю
Conversation.active
Conversation.archived
create_table :conversations do |t|
t.column :status, :integer, default: 0
end