なるようになるブログ

読書感想文かrailsについてかrubyについてか

rails commit log流し読み(2019/02/19)

2019/02/19分のコミットです。

CHANGELOGにのったコミットは以下の通りです。

activerecord/CHANGELOG.md


Fix preparing the configured Action Mailbox ingress in production

actionmailbox/lib/action_mailbox/engine.rbの修正です。

hookの指定順に誤りがあり、production env(reloadingは無効になっている環境)でingressに関する設定がロードされないバグがあったのを修正しています。


appropriate typo fix

actionpack/lib/action_dispatch/testing/integration.rbのdocの修正です。

appropriateapproriateにタイポしている箇所があったのを修正しています。


Add combining callback conditions [skip ci] (#35313)

rails guideのActive Record Callbacksの修正です。

callbackのconditionに:if:unless両方指定した場合について説明したCombining Callback Conditionsセクションを追加しています。


Delete documentation inconsistency 'finally' for AR callbacks [ci skip] (#35303)

rails guideのActive Record CallbacksActive Record Validationsの修正です。

callbackについて説明している箇所のグラマーの修正を行っています。


Merge pull request #35310 from kamipo/dont_allow_invalid_value_matches_to_nil

activemodel/lib/active_model/type/time.rbactiverecord/lib/active_record/relation/query_attribute.rbの修正です。

uuidやdatetime型のカラムに不正な値を指定してwhereを実行した場合(e.g. where(uuid: "2"))に、値がnullなデータが結果に一致しまっていた(IS NULLという条件でSQLが実行されてしまっていた)のを、一致しないよう修正しています。

# before
User.where(uuid: "2")
# => User Load (0.4ms)  SELECT "users".* FROM "users" WHERE "users"."uuid" IS NULL LIMIT $1  [["LIMIT", 11]]

# after
User.where(uuid: "2")
# => User Load (2.9ms)  SELECT "users".* FROM "users" WHERE "users"."uuid" = $1 LIMIT $2  [["uuid", nil], ["LIMIT", 11]]

Rails 5.1までの挙動と合わせる為。


Update active_record_callbacks.md [ci skip]

rails guideのActive Record Callbacksの修正です。

Combining Callback Conditionsの項、callbackの実行について説明している箇所で、happenexecuteに修正しています。

executeの方が用語として正しい為、という理由だったのですが、既存の箇所でhappenを使っている箇所が大量にあるため、後ほどRevertされています。


Introduce delete_by and destroy_by methods to ActiveRecord::Relation

activerecord/lib/active_record/querying.rbactiverecord/lib/active_record/relation.rbの修正です。

ActiveRecord::Relationdelete_byメソッド及びdestroy_byメソッドを追加しています。

destroy_alldelete_allのconditionをメソッドに指定出来るバージョンのメソッドです。元々同様の事をやりたい場合、find_bywhereに条件を指定してdestroy_alldelete_allを使う、という事をやっていたのですが、それらの条件をメソッドに直接指定出来るようになっています。

# Before
unreads.where(readable: readable).destroy_all
unreads.where(readable: readable).delete_all


# After
unreads.destroy_by(readable: readable)
unreads.delete_by(readable: readable)

Revert "Merge pull request #35324 from sharang-d/patch-2"

先のhappenexecuteに修正した対応をRevertしています。