2020/07/14分のコミットです。
CHANGELOGにのったコミットは以下の通りです。
- Allow default to be configured for Enum.
- Allow attribute's default to be configured but keeping its own type.
Merge pull request #39820 from kamipo/enum_default
activerecord/lib/active_record/attributes.rb
、
activerecord/lib/active_record/enum.rb
の修正です。
Enumにデフォルト値を指定出来るよう対応しています。
class Book < ActiveRecord::Base enum status: [:proposed, :written, :published], _default: :published end Book.new.status # => "published"
Allow attribute's default to be configured but keeping its own type
activerecord/lib/active_record/attributes.rb
の修正です。
attribute
のdefaultを指定した場合に、typeが強制的にType::Value
になってしまっていたのを、元のtypeを維持するよう修正しています。
class Post < ActiveRecord::Base attribute :written_at, default: -> { Time.now.utc } end # Rails 6.0 Post.type_for_attribute(:written_at) # => #<Type::Value ... precision: nil, ...> # Rails 6.1 Post.type_for_attribute(:written_at) # => #<Type::DateTime ... precision: 6, ...>