2022/11/24分のコミットです。
CHANGELOGにのったコミットは以下の通りです。
- Add a build persistence method
- Allow per attribute setting of YAML permitted classes (safe load) and unsafe load.
has_one
andbelongs_to
associations now define areset_association
method on the owner model (whereassociation
is the name of the association).- Avoid validating
belongs_to
association if it has not changed. - Allow disabling methods generated by
ActiveRecord.enum
.
actioncable/CHANGELOG.md
activerecord/lib/active_record/persistence.rb
の修正です。
persistanceにbuild
メソッドを追加しています。new
メソッドのラッパーなのですが、attributeをArrayで指定しての複数オブジェクトのまとめての作成などが出来るようになっています。
User.build([{ first_name: 'Jamie' }, { first_name: 'Jeremy' }]) # blockを指定した場合、blockは全てのオブジェクトで実行される User.build([{ first_name: 'Jamie' }, { first_name: 'Jeremy' }]) do |u| u.is_admin = false end
Validate ActiveStorage::Blob io is rewindable
activestorage/app/models/active_storage/blob.rb
の修正です。
ActiveStorage::Blob.create_and_upload!
のioパラメータにrewindableじゃないオブジェクトが指定された場合にArgumentError
をraiseするよう修正しています。
activerecord/lib/active_record/attribute_methods/serialization.rb
、
activerecord/lib/active_record/coders/yaml_column.rb
の修正です。
serialize
メソッドで、permitted classes 及び unsafe loadの設定を、attribute毎に指定出来るよう修正しています。
class User < ActiveRecord::Base serialize :preferences, yaml: { permitted_classes: [Symbol, Time] } end
actionview/lib/action_view/helpers/tags/select.rb
の修正です。
grouped/nested collectionsをselect
に指定した場合に、collectionの末尾に指定した要素がselect
tagのattributeとして使われるよう修正しています。
<%= form.select :foo, [["North America", [["United States","US"],["Canada","CA"]], { disabled: "disabled" }]] %> # => <select><optgroup label="North America" disabled="disabled"><option value="US">United States</option><option value="CA">Canada</option></optgroup></select>
Allow resetting singular associations
activerecord/lib/active_record/associations.rb
、
activerecord/lib/active_record/associations/builder/singular_association.rb
の修正です。
has_one
、及び、belongs_toassociationを使用している場合に、そのassociationのcacheをアンロードする為の
reset_association(
association`部分はassociation名)メソッドが使用出来るよう修正しています。
class Account < ApplicationRecord has_one :beneficiary end account.reset_beneficiary
Merge pull request #45119 from p8/guides/add-cors-to-security-guide
rails guideのSecuring Rails Applications
の修正です。
CORSの対応方法について説明した、Cross-Origin Resource Sharing
の項を追加しています。
Merge pull request #46440 from okuramasafumi/add-active-support-note-to-contribution-guide
rails guideのHow to contribute to Ruby on Rails
の修正です。
Do you intend to add a new feature or change an existing one?
の項に、Active Supportのcore extensionsの変更は基本的にはrejectされる、そのような変更を行いたい場合、Ruby本体へ提案を行う方が良い、という説明を追加しています。
Inline QueryConstraints
module into Persistence
Active Recordの修正です。
query_constraints
に関する処理を専用のmoduleで行っていたのを、Persistence
内で処理を定義するよう修正しています。専用のmoduleで行う程の処理の量では無いため。
Avoid warning when loading YAMLColumn generated by old versions of Rails on Ruby 2.7
activerecord/lib/active_record/coders/yaml_column.rb
の修正です。
Rails + Ruby 2.7 で生成したYAMLColumnをロードした場合に未初期化に関するwarningが出ていたのを修正しています。
feat: restore Action Cable Redis pub/sub listener on connection failure
actioncable/lib/action_cable/subscription_adapter/redis.rb
の修正です。
Action CableのRediのpub/sub adapterで、Redisのconnectionが切れた場合、自動で再接続するよう修正しています。
Avoid validating belongs_to
association if it has not changed
Active Recordの修正です。
required: true
なbelongs_to
associationが定義されている場合、レコード更新時に必ずそのassociationの存在チェックをするqueryが実行されていたのを、associationの値が変更されていない場合は、そのチェックを実行しないよう修正しています。この挙動は、config.active_record.belongs_to_required_validates_foreign_key
にtrueを指定、または、load_defaults 7.1
を指定した場合に使用されるようになっています。
option to disable all methods that ActiveRecord.enum generates
activerecord/lib/active_record/enum.rb
の修正です。
オプションで、ActiveRecord.enum
のメソッドを全て生成しないように出来るよう修正しています。生成したく無い場合は、_instance_methods
にfalseを指定すれば良いようになっています。
class Book < ApplicationRecord enum status: [:proposed, :written], _instance_methods: false end
LoggerThreadSafeLevel only impact the receiving logger
activesupport/lib/active_support/logger_thread_safe_level.rb
の修正です。
LoggerSilence
がreceiverのloggerだけでなく、全てのloggerに影響を与えてしまう(全てのloggerの出力を抑止してしまう)バグがあったのを修正しています。