mysql - N+1 query with rails polymorphic association -
i have 2 models. album class album < activerecord::base has_one :post, as: :post_module, dependent: :destroy end post (which has title attribute) class post < activerecord::base belongs_to :post_module, polymorphic: true end and here template <% @albums.each |album| %> <tr> <td> <%= link_to album.post.title, edit_admin_album_path(album) %> <br/> </td> </tr> <% end %> i tried use :includes , :references avoid n + 1 query. def index @albums = album.includes(:post).references(:post).to_a end but seems n + 1 query still occurs. what's wrong this? sql (0.2ms) select `albums`.`id` t0_r0, `albums`.`product_num` t0_r1, `albums`.`created_at` t0_r2, `albums`.`updated_at` t0_r3, `posts`.`id` t1_r0, `posts`.`title` t1_r1, `posts`.`date` t1_r2, `posts`.`post_module_id` t1_r3, `posts`.`post_module_type` t1_r4, `posts`.`created_at` t1_r5, `posts`.`updated_at` t1_r6 `albums` lef...