{"published":"2015-06-15 01:16:40","title":"find_by_sql \u3057\u305f\u30ec\u30b3\u30fc\u30c9\u3067 preload \u3059\u308b\u65b9\u6cd5","provider_url":"https://hatena.blog","blog_title":"\u304a\u3082\u3057\u308dweb\u30b5\u30fc\u30d3\u30b9\u958b\u767a\u65e5\u8a18","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fwillnet.hateblo.jp%2Fentry%2F2015%2F06%2F15%2F011640\" title=\"find_by_sql \u3057\u305f\u30ec\u30b3\u30fc\u30c9\u3067 preload \u3059\u308b\u65b9\u6cd5 - \u304a\u3082\u3057\u308dweb\u30b5\u30fc\u30d3\u30b9\u958b\u767a\u65e5\u8a18\" class=\"embed-card embed-blogcard\" scrolling=\"no\" frameborder=\"0\" style=\"display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;\"></iframe>","categories":["rails"],"height":"190","author_url":"https://blog.hatena.ne.jp/willnet/","version":"1.0","image_url":null,"author_name":"willnet","url":"https://willnet.hateblo.jp/entry/2015/06/15/011640","provider_name":"Hatena Blog","type":"rich","description":"\u3069\u3046\u3057\u3066\u3082 AR \u306e query methods \u3060\u3051\u3067\u306f\u8981\u6c42\u3092\u6e80\u305f\u305b\u306a\u3044\u5834\u5408\u306e\u6700\u5f8c\u306e\u624b\u6bb5\u3068\u3057\u3066\u3001find_by_sql \u30e1\u30bd\u30c3\u30c9\u304c\u3042\u308a\u307e\u3059\u3002\u7686\u3055\u3093\u3088\u304f\u4f7f\u3063\u3066\u308b\u3068\u601d\u3046\u306e\u3067\u3059\u304c\u3001\u623b\u308a\u5024\u306e\u30ec\u30b3\u30fc\u30c9\u304b\u3089\u3055\u3089\u306b association \u3092\u30ed\u30fc\u30c9\u3057\u3088\u3046\u3068\u3059\u308b\u3068 N+1 \u306b\u306a\u308b\u30b1\u30fc\u30b9\u304c\u3042\u308a\u307e\u3059\u3002\u304b\u3068\u3044\u3063\u3066 User.preload(:comments).find_by_sql(sql) \u306e\u3088\u3046\u306b\u3057\u3066\u3082\u671f\u5f85\u901a\u308a\u306b\u306f\u52d5\u304d\u307e\u305b\u3093\u3002\u5358\u7d14\u306b preload \u90e8\u5206\u304c\u7121\u8996\u3055\u308c\u308b\u3060\u3051\u3067\u3059\u3002 \u3067\u306f\u3069\u306e\u3088\u3046\u306b\u66f8\u3044\u305f\u3089\u3088\u3044\u3067\u3057\u3087\u3046\u304b\u3002 \u6b21\u306e\u3088\u3046\u306b\u66f8\u304f\u3068\u671f\u5f85\u901a\u308a\u306b\u52d5\u304d\u307e\u3059(Rails 4.2.1 \u3067\u8a66\u3057\u3066\u3044\u307e\u3059)\u3002 record\u2026","width":"100%","blog_url":"https://willnet.hateblo.jp/"}