なるようになるブログ

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

rails commit log流し読み(2018/05/26)

2018/05/26分のコミットです。

CHANGELOGへの追加はありませんでした。


Fix different_target? to respect custom primary key counter

activerecord/lib/active_record/associations/belongs_to_association.rbの修正です。

BelongsToAssociation#different_target?メソッドでrecordが変更されているかどうかをチェックする際、id attribute決め打ちで値を見ていたのを、primary_keyに指定されているattributeの値を確認するよう修正しています。


Fix belongs_to_counter_cache_after_update to respect custom primary key counter

activerecord/lib/active_record/associations/builder/belongs_to.rbの修正です。

belongs_to associationsでprimary keyオプションが指定されていた場合に、counter_cacheの更新後のcallback処理で誤ったオブジェクトを参照してしまっていたのを、primary keyに指定されたattributeを使用して正しいオブジェクトを参照するよう修正しています。


Avoid a subquery in updating counter cache

activerecord/lib/active_record/associations/builder/belongs_to.rbactiverecord/lib/active_record/counter_cache.rbの修正です。

先の修正の影響でcounter cacheの更新の際にsubqueryが使われるようになってしまっていたのを修正しています。MySQLだとUPDATE + subqueryは動作しない為。