2023/09/02分のコミットです。
CHANGELOGにのったコミットは以下の通りです。
activemodel/CHANGELOG.md
- Support composite identifiers in
to_key - Fix
change_columnnot settingprecision: 6ondatetimecolumns when using 7.0+ Migrations and SQLite. - Add validation option for
enum - Change
has_secure_tokendefault toon: :initialize
Add CHANGELOG entries for ActiveModel::Conversion#to_key changes
activemodel/CHANGELOG.md、
activerecord/CHANGELOG.mdの修正です。
to_keyメソッドでcomposite keysをサポートするよう修正した、Support composite identifiers in to_keyについてCHANGELOGにエントリーを追加しています。
Document where support for AR normalizes
Active Recordの修正です。
ActiveRecord::Base.normalizesで指定した値はwhereにも影響を与える旨ドキュメントにexampleを追加、及び、挙動を確認する為のテストを追加しています。
[skip ci] Document using FinderMethods.find on composite primary key models
activerecord/lib/active_record/relation/finder_methods.rbのdocの修正です。
FinderMethods.findのドキュメントにcomposite primary keyを使用している場合の挙動の説明を追加しています。
Fix DescendantsTrackerTest when ran in isolation
activesupport/lib/active_support/descendants_tracker.rbの修正です。
Remove useless include in DescendantsTrackerの対応の影響で、DescendantsTrackerのテストがコケるようになってしまっていたのを修正しています。
[skip ci] ActiveModel notable changes added to 7.1 release note
rails guideのRuby on Rails 7.1 Release Notesの修正です。
Active ModelのNotable changesについての説明を追加しています。
Fix change_column not setting precision for sqlite
activerecord/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb、
activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rbの修正です。
SQLite3 adapter + バージョンが7.0以上のmigrationファイルで、datetimeカラムに対するprecision: 6が設定されないバグがあったのを修正しています。
Make enums validatable without raising error (#49100)
activerecord/lib/active_record/enum.rbの修正です。
enumに対してvalidationの挙動を指定出来るよう修正しています。saveより前にvalidationを実行したい場合、enumにvalidate: trueを指定すれば良いようになっています。
class Contract < ApplicationRecord enum :status, %w[in_progress completed], validate: true end Contract.new(status: "unknown").valid? # => false Contract.new(status: nil).valid? # => false Contract.new(status: "completed").valid? # => true
また、validateにはallow_nilなどのオプションも指定出来るようになっています(内部的にはvalidates_inclusion_ofが使用されるようになっています)。
class Contract < ApplicationRecord enum :status, %w[in_progress completed], validate: { allow_nil: true } end Contract.new(status: "unknown").valid? # => false Contract.new(status: nil).valid? # => true Contract.new(status: "completed").valid? # => true
Merge pull request #49112 from gmcgibbon/cpk_id_docs
activerecord/lib/active_record/attribute_methods/primary_key.rb、
activerecord/lib/active_record/model_schema.rbのdocの修正です。
id関係のメソッド(e.g: id、id_before_type_cast)にComposite Primary Keyを使用している場合の挙動についての説明を追加しています。
Change has_secure_token default to on: :initialize
Active Record、railtiesの修正です。
has_secure_tokenを使用している場合の値の設定タイミングのデフォルトをconfig.active_record.generate_secure_token_onで指定出来るよう修正しています。既存の挙動は:create(作成時に設定)ですが、config.active_record.generate_secure_token_onに:initializeを指定する、または、load_defaults 7.1を指定している場合、modelの初期化時に設定するようになります。
Use the released version of trilogy
Gemfileの修正です。
trilogy gemを使用するのにRubygemsにリリースされているバージョンを使用するよう修正しています。
Merge pull request #49067 from p8/performance/securerandom-choose
activesupport/lib/active_support/core_ext/securerandom.rbの修正です。
Ruby 3.3以上の場合、SecureRandom.base36/base58メソッドで値を生成する際にSecureRandom.alphanumeric + charsオプションを指定するよう修正しています。元の処理よりこちらの方が高速な為。
参考: Feature #18183: make SecureRandom.choose public
Merge pull request #49065 from RuhmUndAnsehen/fix-_to_partial_path-model_name
activemodel/lib/active_model/conversion.rbの修正です。
ActiveModel::Conversion._to_partial_pathメソッドで、定義されている場合modelのmodel_nameの値をpartial pathとして使用するよう修正しています。他のpath参照系のメソッドと挙動を合わせる為。
Make sure the message format doesn't change
activesupport/lib/active_support/messages/metadata.rbの修正です。
use_message_serializer_for_metadataがfalseの場合、ActiveSupport::MessageVerifierが生成するメッセージがが古いRailsで生成したデータから変わらないよう修正しています。