なるようになるブログ

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

rails commit log流し読み(2022/07/05)

2022/07/05分のコミットです。

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

activerecord/CHANGELOG.md


Improve working with PostgreSQL schemas

Active Recordの修正です。

PostgreSQLで明示的にschemaが指定されている場合に、create_join_table等の一部のmigrationメソッドがschemaを考慮した動作になってなかったのを修正しています。


Merge pull request #45508 from malis/patch-3

actionview/app/assets/javascripts/rails-ujs/features/remote.coffeeの修正です。

HTTPメソッド名を取得するのにelement.methodを使用していたのを、getAttributeを使用するよう修正しています。element.methodに明示的に値が指定されてしまっているような場合も、値を正しく取得出来るようにする為。


Merge pull request #37944 from vlado/with_cte

Active Recordの修正です。

common table expressionsを使用してActiveRecord::Relationを取得するためのwithメソッドを追加しています。

Post.with(posts_with_comments: Post.where("comments_count > ?", 0))
# => ActiveRecord::Relation
# WITH posts_with_comments AS (SELECT * FROM posts WHERE (comments_count > 0)) SELECT * FROM posts

Post.with(posts_with_tags: Post.where("tags_count > ?", 0)).joins("JOIN posts_with_tags ON posts_with_tags.id = posts.id")
# => ActiveRecord::Relation
# WITH posts_with_tags AS (
#   SELECT * FROM posts WHERE (tags_count > 0)
# )
# SELECT * FROM posts JOIN posts_with_tags ON posts_with_tags.id = posts.id

Fixed flaky test cases in 'test/cases/relation/merging_test.rb'.

activerecord/test/cases/relation/merging_test.rbの修正です。

assertionで値を比較する際に、値をidでsortしてからチェックするよう修正しています。 sortを指定しないと結果が不定になる為。