class Degree < ApplicationRecord
belongs_to :user
enum :degree_type, {
high_school: 'high_school',
associate: 'associate',
bachelor: 'bachelor',
masters: 'masters',
doctoral: 'doctoral'
}, default: 'high_school'
end
u = User.last
u.degrees.degree_types
{"high_school"=>"high_school",
"associate"=>"associate",
"bachelor"=>"bachelor",
"masters"=>"masters",
"doctoral"=>"doctoral"}
工作正常..
尝试使用枚举创建新记录。
第一个
没有错误,是否有效?
u.degrees
[]
不,不,不
u.update(degrees: :high_school)
other_array.each { |val| raise_on_type_mismatch!(val) }
如何在枚举类型中创建新的ActiveRecord记录?
1条答案
按热度按时间wtlkbnrh1#
我看不出在用户记录上使用
update
会创建一个新的学位记录的任何理由。