Rails の PRを見て気になったところ

数日前に以下のPRが目について、where.missing や where.associated って何だろうとなったので、確認してみた。 見たPRはこちら

where.missing(:association を指定)

これは関連先のデータが missing == 空 のデータを返す。 例えば post というテーブルに対し comments というテーブルがあった場合以下のようなSQLになる

Post.where.missing(:comments)
=> "SELECT `posts`.* FROM `posts` LEFT OUTER JOIN `comments` `comments` ON `comments`.`deleted_at` IS NULL  AND `comments`.`post_id` = `posts`.`id` WHERE `comments`.`id` IS NULL"

where.associated(:associaton を指定)

これはmissingとは逆で関連先のデータを変えず。

あまり使っていなかったので、また少し色々見ていく