Rails
【Rails】eager_load, preload, joins入門
· ☕ 1 分で読めます
joins 1 2 [1] pry(main)> User.joins(:tags) User Load (21.3ms) SELECT `users`.* FROM `users` INNER JOIN `registered_tags` ON `registered_tags`.`user_id` = `users`.`id` INNER JOIN `tags` ON `tags`.`id` = `registered_tags`.`tag_id` 1 2 3 select * from tables inner join other_tables のオーソドックスな形。 eager_load 1 2 [3] pry(main)> User.eager_load(:tags) SQL (0.7ms) SELECT `users`.`id` AS t0_r0, `users`.`twitter_id` AS t0_r1, `users`.`uuid` AS t0_r2, `users`.`name` AS t0_r3, `users`.`description`