{"id":26168,"date":"2021-08-01T08:08:09","date_gmt":"1970-01-01T00:00:00","guid":{"rendered":"http:\/\/www.sejuku.net\/blog\/?p=26168"},"modified":"2024-05-06T11:43:39","modified_gmt":"2024-05-06T02:43:39","slug":"%e3%80%90rails%e5%85%a5%e9%96%80%e3%80%91includes%e3%81%ae%e4%bd%bf%e3%81%84%e6%96%b9%e3%81%be%e3%81%a8%e3%82%81","status":"publish","type":"post","link":"https:\/\/www.sejuku.net\/blog\/26168","title":{"rendered":"\u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\/order\u3092\u691c\u8a0e\u3057\u3088\u3046"},"content":{"rendered":"<p>\u307f\u306a\u3055\u3093\u306f\u30012\u3064\u306e\u95a2\u9023\u4ed8\u3051\u3089\u308c\u305f\u30c6\u30fc\u30d6\u30eb\u3092\u6271\u3063\u3066\u3044\u308b\u3068\u304d\u306b\u3001<span style=\"color: #0000ff;\"><strong>\u3069\u306e\u3088\u3046\u306b\u5024\u3092\u53d6\u308a\u51fa\u3057\u3066\u3044\u307e\u3059\u304b\uff1f<\/strong><\/span><\/p>\n<p>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u6c17\u306b\u305b\u305a\u3001<span style=\"color: #339966;\"><strong>all<\/strong><\/span>\u3084<span style=\"color: #339966;\"><strong>join<\/strong><\/span>\u3092\u4f7f\u3063\u3066\u3001<span style=\"color: #ff0000;\"><strong>N+1\u554f\u984c<\/strong><\/span>\u3092\u767a\u751f\u3055\u305b\u3066\u3044\u307e\u305b\u3093\u304b\uff1f<\/p>\n<p>\u305d\u308c\u3068\u3082\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u6c17\u306b\u3057\u3066\u3001<span style=\"color: #339966;\"><strong>includes<\/strong><\/span>\u3084<span style=\"color: #339966;\"><strong>preload<\/strong><\/span>\u3001<span style=\"color: #339966;\"><strong>eager_load<\/strong><\/span>\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u304b\uff1f<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u4e0a\u3052\u308b\u305f\u3081\u306e1\u3064\u306e\u89e3\u6cd5\u3067\u3042\u308bincludes\u3092\u53d6\u308a\u4e0a\u3052\u3001\u4ee5\u4e0b\u306e\u5185\u5bb9\u3092\u8aac\u660e\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<div style=\"padding: 10px 5px 10px 20px; margin-bottom: 20px; border: 5px solid #ffe4e2;\">\u30fbN+1\u554f\u984c\u3068\u306f<br \/>\n\u30fb2\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5<br \/>\n\u30fb\u30cd\u30b9\u30c8\u3055\u308c\u305f\u8907\u6570\u306e\u30c6\u30fc\u30d6\u30eb\u304b\u3089includes\u3067\u30c7\u30fc\u30bf\u3092\u4e00\u62ec\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\n<\/div>\n<p>\u3055\u3089\u306b\u3001\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u30c7\u30fc\u30bf\u3092\u4e26\u3079\u66ff\u3048\u305f\u72b6\u614b\u3067\u53d6\u5f97\u3059\u308b\u305f\u3081\u306e<span style=\"color: #54a870;\"><strong>order<\/strong><\/span>\u3092\u53d6\u308a\u4e0a\u3052\u3001\u4ee5\u4e0b\u306e\u5185\u5bb9\u3092\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<div style=\"padding: 10px 5px 10px 20px; margin-bottom: 20px; border: 5px solid #ffe4e2;\">\u30fb\u30c7\u30fc\u30bf\u3092\u4e26\u3079\u66ff\u3048\u308b\u65b9\u6cd5<br \/>\n\u30fb\u8907\u6570\u306e\u30ab\u30e9\u30e0\u3092\u4f7f\u3063\u3066\u4e26\u3079\u66ff\u3048\u308b\u65b9\u6cd5<br \/>\n\u30fbreorder\u306e\u4f7f\u3044\u3069\u3053\u308d<br \/>\n\u30fborder_as_specified gem\u3092\u4f7f\u3063\u3066\u9806\u756a\u30921\u30641\u3064\u6307\u5b9a\u3057\u3066\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\n<\/div>\n<p>\u30c7\u30fc\u30bf\u304c\u5c11\u306a\u3044\u3046\u3061\u306f\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306b\u554f\u984c\u3092\u611f\u3058\u306a\u304f\u3066\u3082\u3001\u30c7\u30fc\u30bf\u304c\u591a\u304f\u306a\u3063\u305f\u3068\u304d\u306e\u3053\u3068\u3092\u8003\u3048\u3066\u3001\u4eca\u306e\u3046\u3061\u306b<span style=\"color: #0000ff;\"><strong>N+1\u554f\u984c\u3092\u89e3\u6c7a\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\uff01<\/strong><\/span><\/p>\n<p>\u307e\u305f\u3001\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3066\u304b\u3089Rails\u3067\u4e26\u3079\u66ff\u3048\u308b\u3088\u308a\u3082\u3001\u30c7\u30fc\u30bf\u3092\u4e26\u3079\u66ff\u3048\u305f\u72b6\u614b\u3067\u53d6\u5f97\u3057\u305f\u307b\u3046\u304c\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u7684\u306b\u3082\u6709\u5229\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u3001<span style=\"color: #0000ff;\"><strong>order\u306e\u4f7f\u3044\u65b9\u3082\u3042\u308f\u305b\u3066\u30de\u30b9\u30bf\u30fc\u3057\u3066\u3057\u307e\u3044\u307e\u3057\u3087\u3046\u3002<\/strong><\/span><\/p>\n<p>\u3067\u306f\u3001\u9806\u756a\u306b\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u306d\u3002<\/p>\n<h2>includes\u3068\u306f\u3001N+1\u554f\u984c\u3068\u306f<\/h2>\n<p>includes\u306f\u3001\u95a2\u9023\u4ed8\u3051\u3089\u308c\u305f2\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u30c7\u30fc\u30bf\u3092\u53c2\u7167\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<\/p>\n<p>\u4e3b\u306bN+1\u554f\u984c\u3092\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306b\u5229\u7528\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>N+1\u554f\u984c\u306b\u3064\u3044\u3066\u306f\u3001\u5177\u4f53\u4f8b\u3092\u898b\u308b\u3068\u89e3\u308a\u3084\u3059\u3044\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3001\u65e9\u901f\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306a2\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n<table id=\"tablepress-546\" class=\"tablepress tablepress-id-546\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">\u30c6\u30fc\u30d6\u30eb<\/th><th class=\"column-2\">\u30ab\u30e9\u30e0<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">User\u30c6\u30fc\u30d6\u30eb<\/td><td class=\"column-2\">name<br \/>\nposts\uff08has_many\uff09<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">Post\u30c6\u30fc\u30d6\u30eb<\/td><td class=\"column-2\">user_id\uff08belongs_to\uff09<br \/>\ntitle<br \/>\nmonth<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-546 from cache -->\n<p>\u305d\u3057\u3066\u3001User\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u3001Post\u30c6\u30fc\u30d6\u30eb\u306etitle\u3092\u53c2\u7167\u3059\u308b\u65b9\u6cd5\u3092\u8003\u3048\u307e\u3059\u3002<\/p>\n<p>\u4e00\u756a\u624b\u3063\u53d6\u308a\u65e9\u3044\u306e\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3067\u3059\u306d\u3002<\/p>\n<pre class=\"decode:true \" >User.all.each { |user| user.posts.each{ |post| puts \"#{user.name} \/ #{post.title}\"} }<\/pre>\n<p>\u3057\u304b\u3057\u3001\u3053\u308c\u3067\u306f\u3001\u30c7\u30fc\u30bf\u6570\u304c\u591a\u304f\u306a\u3063\u305f\u3068\u304d\u306b\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306b\u554f\u984c\u304c\u767a\u751f\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  User Load (0.2ms)  SELECT \"users\".* FROM \"users\"\r\n  Post Load (0.2ms)  SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"user_id\" = ?  [[\"user_id\", 1]]\r\n\u5c71\u7530\u592a\u90ce \/ \u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71\r\n  Post Load (0.1ms)  SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"user_id\" = ?  [[\"user_id\", 2]]\r\n\u9577\u702c\u6765 \/ \u6700\u8fd1\u5c11\u3057\u6c17\u306b\u306a\u3063\u305f\u3053\u3068\r\n  Post Load (0.1ms)  SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"user_id\" = ?  [[\"user_id\", 3]]\r\n\u7acb\u5ddd\u88d5\u7f8e \/ \u6628\u65e5\u306e\u51fa\u6765\u4e8b\r\n\u7acb\u5ddd\u88d5\u7f8e \/ \u5c71\u767b\u308a\u306b\u884c\u304d\u307e\u3057\u305f\r\n\u7acb\u5ddd\u88d5\u7f8e \/ Ruby on Rails\u306e\u65e5\r\n  Post Load (0.1ms)  SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"user_id\" = ?  [[\"user_id\", 4]]\r\n\u524d\u7530\u9054\u90ce \/ \u53cb\u4eba\u304c\u7d50\u5a5a\u3057\u307e\u3057\u305f\r\n\u524d\u7530\u9054\u90ce \/ \u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4\r\n  Post Load (0.1ms)  SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"user_id\" = ?  [[\"user_id\", 5]]\r\n\u7d30\u5ddd\u4fee\u4e8c \/ \u697d\u3057\u3044\u4f11\u65e5\u306e\u904e\u3054\u3057\u65b9\r\n  Post Load (0.1ms)  SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"user_id\" = ?  [[\"user_id\", 6]]\r\n+----+----------+-------------------------+-------------------------+\r\n| id | name     | created_at              | updated_at              |\r\n+----+----------+-------------------------+-------------------------+\r\n| 1  | \u5c71\u7530\u592a\u90ce | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 2  | \u9577\u702c\u6765   | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 3  | \u7acb\u5ddd\u88d5\u7f8e | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 4  | \u524d\u7530\u9054\u90ce | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 5  | \u7d30\u5ddd\u4fee\u4e8c | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 6  | \u6728\u6751\u62d3\u78e8 | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n+----+----------+-------------------------+-------------------------+\r\n6 rows in set<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\u306e\u898b\u304b\u305f\u3092\u8aac\u660e\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306eUser\u30c6\u30fc\u30d6\u30eb\u3092\u8aad\u307f\u8fbc\u3093\u3060\u30bf\u30a4\u30df\u30f3\u30b0\u3067<span style=\"color: #339966;\"><strong>\u300cUser Load (0.1ms)&#8230;\u300d<\/strong><\/span>\u3068\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u540c\u69d8\u306bPost\u30c6\u30fc\u30d6\u30eb\u3092\u8aad\u307f\u8fbc\u3093\u3060\u3068\u304d\u306b<span style=\"color: #339966;\"><strong>\u300cPost Load (0.1ms)&#8230;\u300d<\/strong><\/span>\u3068\u8868\u793a\u3055\u308c\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u304c6\u56de\u8868\u793a\u3055\u308c\u3066\u3044\u307e\u3059\u306d\u3002<\/p>\n<p>\u3064\u307e\u308a\u30016\u540d\u5206\u306epost.title\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306b\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b6\u56de\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3044\u308b\u30ef\u30b1\u3067\u3059\u304c\u3001includes\u3092\u4f7f\u3046\u3068\u3053\u308c\u30921\u56de\u306b\u524a\u6e1b\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>1\u56de\u306e\u30a2\u30af\u30bb\u30b9\u3067\u89e3\u6c7a\u3067\u304d\u308b\u3082\u306e\u3092\u30016\u56de\u3082\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3044\u308b\u306e\u3067\u554f\u984c\u3068\u3055\u308c\u3066\u3044\u3066\u3001\u4e00\u822c\u7684\u306b<span style=\"color: #ff0000;\"><strong>N+1\u554f\u984c<\/strong><\/span>\u304c\u767a\u751f\u3057\u3066\u3044\u308b\u3068\u8a00\u3044\u307e\u3059\u3002<\/p>\n<p>\u5177\u4f53\u7684\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067Post\u30c6\u30fc\u30d6\u30eb\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u56de\u6570\u30921\u56de\u306b\u6e1b\u3089\u305b\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >User.includes(:posts).each { |user| user.posts.each{ |post| puts \"#{user.name} \/ #{post.title}\"} }<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  User Load (0.1ms)  SELECT \"users\".* FROM \"users\"\r\n  Post Load (0.3ms)  SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"user_id\" IN (1, 2, 3, 4, 5, 6)\r\n\u5c71\u7530\u592a\u90ce \/ \u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71\r\n\u9577\u702c\u6765 \/ \u6700\u8fd1\u5c11\u3057\u6c17\u306b\u306a\u3063\u305f\u3053\u3068\r\n\u7acb\u5ddd\u88d5\u7f8e \/ \u6628\u65e5\u306e\u51fa\u6765\u4e8b\r\n\u7acb\u5ddd\u88d5\u7f8e \/ \u5c71\u767b\u308a\u306b\u884c\u304d\u307e\u3057\u305f\r\n\u7acb\u5ddd\u88d5\u7f8e \/ Ruby on Rails\u306e\u65e5\r\n\u524d\u7530\u9054\u90ce \/ \u53cb\u4eba\u304c\u7d50\u5a5a\u3057\u307e\u3057\u305f\r\n\u524d\u7530\u9054\u90ce \/ \u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4\r\n\u7d30\u5ddd\u4fee\u4e8c \/ \u697d\u3057\u3044\u4f11\u65e5\u306e\u904e\u3054\u3057\u65b9\r\n+----+----------+-------------------------+-------------------------+\r\n| id | name     | created_at              | updated_at              |\r\n+----+----------+-------------------------+-------------------------+\r\n| 1  | \u5c71\u7530\u592a\u90ce | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 2  | \u9577\u702c\u6765   | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 3  | \u7acb\u5ddd\u88d5\u7f8e | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 4  | \u524d\u7530\u9054\u90ce | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 5  | \u7d30\u5ddd\u4fee\u4e8c | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 6  | \u6728\u6751\u62d3\u78e8 | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n+----+----------+-------------------------+-------------------------+\r\n6 rows in set<\/pre>\n<p>\u3042\u3068\u3067\u8a66\u3057\u3066\u3082\u3089\u3044\u307e\u3059\u306e\u3067\u3001\u3053\u3053\u3067\u306f<span style=\"color: #0000ff;\"><strong>\u300cPost Load\u300d\u304c\u3059\u3054\u304f\u6e1b\u3063\u3066\u3044\u308b<\/strong><\/span>\u3068\u3044\u3046\u96f0\u56f2\u6c17\u3060\u3051\u3092\u3064\u304b\u3093\u3067\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>includes\u306e\u52d5\u4f5c\u3092\u7406\u89e3\u3059\u308b\u305f\u3081\u306eWeb\u30a2\u30d7\u30ea\u3092\u4f5c\u6210\u3059\u308b<\/h2>\n<p>Rails\u306e\u52d5\u4f5c\u3092\u7406\u89e3\u3059\u308b\u305f\u3081\u306b\u3001<span style=\"color: #339966;\"><strong>scaffold<\/strong><\/span>\u3092\u4f7f\u3063\u3066Web\u30a2\u30d7\u30ea\u3092\u4f5c\u3063\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>scaffold\u306e\u4f7f\u3044\u65b9\u306f\u3001\u4ee5\u4e0b\u306e\u8a18\u4e8b\u3067\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u305c\u3072\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n            <a href=\"https:\/\/www.sejuku.net\/blog\/26515\" class=\"blog-card-anchor\">\n                <div class=\"blog-card\">\n                <div class=\"blog-card-content\">\n                    <div class=\"blog-card-thumbnail\">\n                    <img decoding=\"async\" class=\"blog-card-thumbnail-img\" src=\"https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2018\/06\/rails-scaffold2-150x86.jpg\">\n                    <\/div>\n                    <div class=\"blog-card-title-wrap\">\n                    <div class=\"blog-card-title\">\u3010Rails\u5165\u9580\u3011\u521d\u3081\u3066\u306eWeb\u30a2\u30d7\u30ea\u958b\u767a\u306a\u3089scaffold\u304c\u6700\u77ed\uff01<\/div>\n                    <div class=\"blog-card-update-date\">\u66f4\u65b0\u65e5\uff1a2024\u5e745\u67086\u65e5<\/div>\n                    <\/div>\n                <\/div>\n                <\/div>\n            <\/a>\n            \n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001<span style=\"color: #339966;\"><strong>app\/samurai\/includes-demo<\/strong><\/span>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067Web\u30a2\u30d7\u30ea\u3092\u4f5c\u6210\u3057\u305f\u5834\u5408\u3092\u4f8b\u306b\u3001\u8aac\u660e\u3092\u7d9a\u3051\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >bin\/rails generate scaffold User name:string\r\nbin\/rails generate scaffold Post user_id:integer title:string month:integer\r\nbin\/rails db:migrate\r\nbin\/rails server<\/pre>\n<h3>\u30c7\u30fc\u30bf\u306e\u6e96\u5099<\/h3>\n<p>Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3092\u8d77\u52d5\u3057\u3066\u30c6\u30fc\u30d6\u30eb\u306b\u30c7\u30fc\u30bf\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<p>scaffold\u3067\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u3001<span style=\"color: #339966;\"><strong>http:\/\/localhost:3000\/users\/new<\/strong><\/span>\u3084\u3001<span style=\"color: #339966;\"><strong>http:\/\/localhost:3000\/posts\/new<\/strong><\/span>\u30671\u3064\u305a\u3064\u30c7\u30fc\u30bf\u3092\u5165\u529b\u3057\u3066\u3082\u69cb\u3044\u307e\u305b\u3093\u3002<\/p>\n<p>\uff081\uff09\u65b0\u3057\u3044<span style=\"color: #339966;\"><strong>\u300c\u7aef\u672b\u300d<\/strong><\/span>\u3092\u8d77\u52d5\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u30921\u884c\u305a\u3064\u9806\u756a\u306b\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >cd app\/samurai\/includes-demo\r\nbin\/rails console<\/pre>\n<p>\uff082\uff09\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >User.create(name:\"\u5c71\u7530\u592a\u90ce\")\r\nUser.create(name:\"\u9577\u702c\u6765\")\r\nUser.create(name:\"\u7acb\u5ddd\u88d5\u7f8e\")\r\nUser.create(name:\"\u524d\u7530\u9054\u90ce\")\r\nUser.create(name:\"\u7d30\u5ddd\u4fee\u4e8c\")\r\nUser.create(name:\"\u6728\u6751\u62d3\u78e8\")\r\nPost.create(user_id:5,title:\"\u697d\u3057\u3044\u4f11\u65e5\u306e\u904e\u3054\u3057\u65b9\" ,month:3)\r\nPost.create(user_id:1,title:\"\u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71\" ,month:2)\r\nPost.create(user_id:3,title:\"\u6628\u65e5\u306e\u51fa\u6765\u4e8b\" ,month:12)\r\nPost.create(user_id:3,title:\"\u5c71\u767b\u308a\u306b\u884c\u304d\u307e\u3057\u305f\" ,month:8)\r\nPost.create(user_id:4,title:\"\u53cb\u4eba\u304c\u7d50\u5a5a\u3057\u307e\u3057\u305f\" ,month:4)\r\nPost.create(user_id:2,title:\"\u6700\u8fd1\u5c11\u3057\u6c17\u306b\u306a\u3063\u305f\u3053\u3068\" ,month:1)\r\nPost.create(user_id:4,title:\"\u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4\" ,month:9)\r\nPost.create(user_id:3,title:\"Ruby on Rails\u306e\u65e5\" ,month:9)\r\nexit<\/pre>\n<p>User\u30c6\u30fc\u30d6\u30eb\u3068Post\u30c6\u30fc\u30d6\u30eb\u306b\u30c7\u30fc\u30bf\u304c\u5165\u529b\u3055\u308c\u3001Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u304c\u7d42\u4e86\u3057\u307e\u3059\u3002<\/p>\n<p>\u30d6\u30e9\u30a6\u30b6\u3067\u30c7\u30fc\u30bf\u3092\u78ba\u8a8d\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\uff083\uff09\u30d6\u30e9\u30a6\u30b6\u3067<span style=\"color: #339966;\"><strong>\u300chttp:\/\/localhost:3000\/users\u300d<\/strong><\/span>\u306b\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2018\/06\/rails-include01.png\" alt=\"rails-include01\" width=\"272\" height=\"313\" class=\"alignnone size-full wp-image-60085\" srcset=\"https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2018\/06\/rails-include01.png 272w, https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2018\/06\/rails-include01-130x150.png 130w, https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2018\/06\/rails-include01-261x300.png 261w\" sizes=\"(max-width: 272px) 100vw, 272px\" \/><\/p>\n<p>\uff084\uff09\u30d6\u30e9\u30a6\u30b6\u3067<span style=\"color: #339966;\"><strong>\u300chttp:\/\/localhost:3000\/posts\u300d<\/strong><\/span>\u306b\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2018\/06\/rails-include02.png\" alt=\"rails-include02\" width=\"435\" height=\"363\" class=\"alignnone size-full wp-image-60086\" srcset=\"https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2018\/06\/rails-include02.png 435w, https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2018\/06\/rails-include02-150x125.png 150w, https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2018\/06\/rails-include02-300x250.png 300w\" sizes=\"(max-width: 435px) 100vw, 435px\" \/><\/p>\n<p>\u3046\u307e\u304f\u767b\u9332\u3055\u308c\u3066\u3044\u307e\u3059\u306d\uff01<\/p>\n<p>\u6b21\u306bUser\u30c6\u30fc\u30d6\u30eb\u3068Post\u30c6\u30fc\u30d6\u30eb\u3092\u95a2\u9023\u4ed8\u3051\u307e\u3059\u3002<\/p>\n<p>\uff085\uff09<span style=\"color: #339966;\"><strong>app\/models\/user.rb<\/strong><\/span>\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7de8\u96c6\u3057\u307e\u3059\u3002<\/p>\n<p>\u5909\u66f4\u524d\uff1a<\/p>\n<pre class=\"decode:true \" >class User < ApplicationRecord\r\nend<\/pre>\n<p>\u5909\u66f4\u5f8c\uff1a<\/p>\n<pre class=\"decode:true \" >class User < ApplicationRecord\r\n  has_many :posts\r\nend<\/pre>\n<p>\uff086\uff09<span style=\"color: #339966;\"><strong>app\/models\/post.rb<\/strong><\/span>\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7de8\u96c6\u3057\u307e\u3059\u3002<\/p>\n<p>\u5909\u66f4\u524d\uff1a<\/p>\n<pre class=\"decode:true \" >class Post < ApplicationRecord\r\nend<\/pre>\n<p>\u5909\u66f4\u5f8c\uff1a<\/p>\n<pre class=\"decode:true \" >class Post < ApplicationRecord\r\n  belongs_to :user\r\nend<\/pre>\n<p>\u3053\u308c\u3067\u3001\u6e96\u5099\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<h3>hirb gem\u3068hirb-unicode gem\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/h3>\n<p>\u3053\u306e\u5f8c\u3001includes\u306e\u52d5\u4f5c\u3092\u78ba\u8a8d\u3059\u308b\u969b\u3001Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u51fa\u529b\u3057\u305f\u30c7\u30fc\u30bf\u306e\u898b\u6804\u3048\u3092\u826f\u304f\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u4ee5\u4e0b\u306e2\u3064\u306egem\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n<table id=\"tablepress-547\" class=\"tablepress tablepress-id-547\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">gem<\/th><th class=\"column-2\">\u8aac\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">hirb gem<\/td><td class=\"column-2\">\u51fa\u529b\u7d50\u679c\u3092\u8868\u5f62\u5f0f\u3067\u51fa\u529b\u3059\u308b<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">hirb-unicode gem<\/td><td class=\"column-2\">\u30de\u30eb\u30c1\u30d0\u30a4\u30c8\u6587\u5b57\u306e\u8868\u793a\u3092\u88dc\u6b63\u3059\u308b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-547 from cache -->\n<p>\uff081\uff09<span style=\"color: #339966;\"><strong>Gemfile<\/strong><\/span>\u306e\u6700\u7d42\u884c\u306b\u4ee5\u4e0b\u306e\u5185\u5bb9\u3092\u8ffd\u8a18\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >gem 'hirb'\r\ngem 'hirb-unicode'<\/pre>\n<p>\uff082\uff09\u65b0\u3057\u3044<span style=\"color: #339966;\"><strong>\u300c\u7aef\u672b\u300d<\/strong><\/span>\u3092\u8d77\u52d5\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u30921\u884c\u305a\u3064\u9806\u756a\u306b\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >cd app\/samurai\/includes-demo\r\nbundle install<\/pre>\n<p>\u3053\u308c\u3067\u3001<span style=\"color: #339966;\"><strong>hirb gem<\/strong><\/span>\u3068<span style=\"color: #339966;\"><strong>hirb-unicode gem<\/strong><\/span>\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<h2>\u95a2\u9023\u4ed8\u3051\u3089\u308c\u305f2\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u30c7\u30fc\u30bf\u3092\u53c2\u7167\u3059\u308b\u65b9\u6cd5<\/h2>\n<p>\u95a2\u9023\u4ed8\u3051\u3089\u308c\u305f2\u3064\u306e\u30c6\u30fc\u30d6\u30eb\uff08\u4e0a\u3067\u7d39\u4ecb\u3057\u305fUser\u30c6\u30fc\u30d6\u30eb\u3068Post\u30c6\u30fc\u30d6\u30eb\uff09\u3067\u3001<span style=\"color: #0000ff;\"><strong>\u3059\u3079\u3066\u306epost\u306e\u6295\u7a3f\u8005\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5<\/strong><\/span>\u3092\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u3053\u3053\u304b\u3089\u306f\u3001Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u3066\u3001\u5b9f\u884c\u7d50\u679c\u3092\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\uff081\uff09\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u30921\u884c\u305a\u3064\u9806\u756a\u306b\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >bin\/rails console\r\nHirb.enable<\/pre>\n<p>\uff082\uff09\u3059\u3079\u3066\u306epost\u306e\u30c7\u30fc\u30bf\u3092\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306b\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >Post.all<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  Post Load (2.1ms)  SELECT \"posts\".* FROM \"posts\"\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| id | user_id | title            | month | created_at      | updated_at       |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| 1  | 5       | \u697d\u3057\u3044\u4f11\u65e5\u306e...  | 3     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 2  | 1       | \u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71 | 2     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b     | 12    | 2018-06-21 1... | 2018-06-21 14... |\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d...  | 8     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 5  | 4       | \u53cb\u4eba\u304c\u7d50\u5a5a\u3057...  | 4     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 6  | 2       | \u6700\u8fd1\u5c11\u3057\u6c17\u306b...  | 1     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 7  | 4       | \u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4 | 9     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 8  | 3       | Ruby on Rails... | 9     | 2018-06-21 1... | 2018-06-21 14... |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n8 rows in set<\/pre>\n<p>\uff083\uff09\u3059\u3079\u3066\u306euser\u306e\u30c7\u30fc\u30bf\u3092\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306b\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >User.all<\/pre>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  User Load (0.2ms)  SELECT \"users\".* FROM \"users\"\r\n+----+----------+-------------------------+-------------------------+\r\n| id | name     | created_at              | updated_at              |\r\n+----+----------+-------------------------+-------------------------+\r\n| 1  | \u5c71\u7530\u592a\u90ce | 2018-06-21 14:17:20 UTC | 2018-06-21 14:17:20 UTC |\r\n| 2  | \u9577\u702c\u6765   | 2018-06-21 14:17:20 UTC | 2018-06-21 14:17:20 UTC |\r\n| 3  | \u7acb\u5ddd\u88d5\u7f8e | 2018-06-21 14:17:20 UTC | 2018-06-21 14:17:20 UTC |\r\n| 4  | \u524d\u7530\u9054\u90ce | 2018-06-21 14:17:20 UTC | 2018-06-21 14:17:20 UTC |\r\n| 5  | \u7d30\u5ddd\u4fee\u4e8c | 2018-06-21 14:17:20 UTC | 2018-06-21 14:17:20 UTC |\r\n| 6  | \u6728\u6751\u62d3\u78e8 | 2018-06-21 14:17:20 UTC | 2018-06-21 14:17:20 UTC |\r\n+----+----------+-------------------------+-------------------------+\r\n6 rows in set<\/pre>\n<p>\u624b\u9806\uff082\uff09\u3067\u8868\u793a\u3055\u308c\u305fuser_id\u3092\u4f7f\u3063\u3066\u3001\u624b\u9806\uff083\uff09\u3067\u8868\u793a\u3055\u308c\u305fUser\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u8a72\u5f53\u30e6\u30fc\u30b6\u30fc\u3092\u7279\u5b9a\u3057\u3066\u3001name\u3092\u53d6\u5f97\u3059\u308c\u3070ok\u3067\u3059\u306d\u3002<\/p>\n<p>\u3067\u306f\u3001\u305d\u308c\u3092\u5b9f\u73fe\u3059\u308b3\u3064\u306e\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>Post.all<\/h3>\n<p><span style=\"color: #339966;\"><strong>Post.all<\/strong><\/span>\u3067\u3059\u3079\u3066\u306epost\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308c\u3070\u3088\u3055\u305d\u3046\u3067\u3059\u3002<\/p>\n<pre class=\"decode:true \" >Post.all.each { |post| puts \"\u2605 post.id=#{post.id} : post.user.name=#{post.user.name}\" }<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  Post Load (0.1ms)  SELECT \"posts\".* FROM \"posts\"\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 5], [\"LIMIT\", 1]]\r\n\u2605 post.id=1 : post.user.name=\u7d30\u5ddd\u4fee\u4e8c\r\n  User Load (0.0ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 1], [\"LIMIT\", 1]]\r\n\u2605 post.id=2 : post.user.name=\u5c71\u7530\u592a\u90ce\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 3], [\"LIMIT\", 1]]\r\n\u2605 post.id=3 : post.user.name=\u7acb\u5ddd\u88d5\u7f8e\r\n  User Load (0.0ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 3], [\"LIMIT\", 1]]\r\n\u2605 post.id=4 : post.user.name=\u7acb\u5ddd\u88d5\u7f8e\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 4], [\"LIMIT\", 1]]\r\n\u2605 post.id=5 : post.user.name=\u524d\u7530\u9054\u90ce\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 2], [\"LIMIT\", 1]]\r\n\u2605 post.id=6 : post.user.name=\u9577\u702c\u6765\r\n  User Load (0.3ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 4], [\"LIMIT\", 1]]\r\n\u2605 post.id=7 : post.user.name=\u524d\u7530\u9054\u90ce\r\n  User Load (0.2ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 3], [\"LIMIT\", 1]]\r\n\u2605 post.id=8 : post.user.name=\u7acb\u5ddd\u88d5\u7f8e\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| id | user_id | title            | month | created_at      | updated_at       |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| 1  | 5       | \u697d\u3057\u3044\u4f11\u65e5\u306e...  | 3     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 2  | 1       | \u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71 | 2     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b     | 12    | 2018-06-21 1... | 2018-06-21 14... |\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d...  | 8     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 5  | 4       | \u53cb\u4eba\u304c\u7d50\u5a5a\u3057...  | 4     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 6  | 2       | \u6700\u8fd1\u5c11\u3057\u6c17\u306b...  | 1     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 7  | 4       | \u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4 | 9     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 8  | 3       | Ruby on Rails... | 9     | 2018-06-21 1... | 2018-06-21 14... |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n8 rows in set<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\u3067\u2605\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u884c\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>1\u756a\u306epost\u306e\u6295\u7a3f\u8005\u304c<span style=\"color: #0000ff;\"><strong>\u7d30\u5ddd\u4fee\u4e8c<\/strong><\/span>\u3067\u3042\u308b\u3053\u3068\u304c\u53d6\u5f97\u3067\u304d\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305f\u3060\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u306f\u5168\u90e8\u30679\u56de\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u3001<span style=\"color: #ff0000;\"><strong>N+1\u554f\u984c<\/strong><\/span>\u304c\u767a\u751f\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>joins<\/h3>\n<p>\u6b21\u306f<span style=\"color: #339966;\"><strong>joins<\/strong><\/span>\u3092\u4f7f\u3046\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<p>\u8a66\u3057\u3066\u307f\u308b\u3068\u3001<span style=\"color: #339966;\"><strong>Post.all<\/strong><\/span>\u3068\u307b\u3068\u3093\u3069\u540c\u3058\u3067\u3059\u304c\u3001joins\u306f<span style=\"color: #339966;\"><strong>\u5185\u90e8\u7d50\u5408\uff08INNER JOIN\uff09<\/strong><\/span>\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >Post.joins(:user).each { |post| puts \"\u2605 post.id=#{post.id} : post.user.name=#{post.user.name}\" }<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  Post Load (0.2ms)  SELECT \"posts\".* FROM \"posts\" INNER JOIN \"users\" ON \"users\".\"id\" = \"posts\".\"user_id\"\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 5], [\"LIMIT\", 1]]\r\n\u2605 post.id=1 : post.user.name=\u7d30\u5ddd\u4fee\u4e8c\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 1], [\"LIMIT\", 1]]\r\n\u2605 post.id=2 : post.user.name=\u5c71\u7530\u592a\u90ce\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 3], [\"LIMIT\", 1]]\r\n\u2605 post.id=3 : post.user.name=\u7acb\u5ddd\u88d5\u7f8e\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 3], [\"LIMIT\", 1]]\r\n\u2605 post.id=4 : post.user.name=\u7acb\u5ddd\u88d5\u7f8e\r\n  User Load (0.2ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 4], [\"LIMIT\", 1]]\r\n\u2605 post.id=5 : post.user.name=\u524d\u7530\u9054\u90ce\r\n  User Load (0.2ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 2], [\"LIMIT\", 1]]\r\n\u2605 post.id=6 : post.user.name=\u9577\u702c\u6765\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 4], [\"LIMIT\", 1]]\r\n\u2605 post.id=7 : post.user.name=\u524d\u7530\u9054\u90ce\r\n  User Load (0.2ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 3], [\"LIMIT\", 1]]\r\n\u2605 post.id=8 : post.user.name=\u7acb\u5ddd\u88d5\u7f8e\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| id | user_id | title            | month | created_at      | updated_at       |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| 1  | 5       | \u697d\u3057\u3044\u4f11\u65e5\u306e...  | 3     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 2  | 1       | \u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71 | 2     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b     | 12    | 2018-06-21 1... | 2018-06-21 14... |\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d...  | 8     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 5  | 4       | \u53cb\u4eba\u304c\u7d50\u5a5a\u3057...  | 4     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 6  | 2       | \u6700\u8fd1\u5c11\u3057\u6c17\u306b...  | 1     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 7  | 4       | \u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4 | 9     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 8  | 3       | Ruby on Rails... | 9     | 2018-06-21 1... | 2018-06-21 14... |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n8 rows in set<\/pre>\n<p>\u3053\u306e\u65b9\u6cd5\u3067\u3082\u3001\u3084\u306f\u308a<span style=\"color: #ff0000;\"><strong>N+1\u554f\u984c<\/strong><\/span>\u304c\u767a\u751f\u3057\u3066\u3044\u307e\u3059\u306d\u3002<\/p>\n<h3>includes<\/h3>\n<p>3\u3064\u76ee\u306f\u3001<span style=\"color: #339966;\"><strong>includes<\/strong><\/span>\u3092\u4f7f\u3046\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<p>includes\u306f\u3001<span style=\"color: #0000ff;\"><strong>\u6761\u4ef6\u306b\u3088\u3063\u30662\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u307e\u3068\u3081\u308b\u65b9\u6cd5\u304c\u5909\u308f\u308b<\/strong><\/span>\u3068\u3044\u3046\u7279\u5fb4\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u8a73\u7d30\u306f\u7701\u304d\u307e\u3059\u304c\u3001\u4ee5\u4e0b\u306e2\u3064\u306e\u30d1\u30bf\u30fc\u30f3\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>2\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u3092<span style=\"color: #339966;\"><strong>\u5de6\u5916\u90e8\u7d50\u5408\uff08LEFT OUTER JOIN\uff09<\/strong><\/span>\u3057\u3066\u3001\u305d\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u30e1\u30e2\u30ea\u306b\u8aad\u307f\u8fbc\u3080<\/li>\n<li>2\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u305d\u306e\u307e\u307e\u30e1\u30e2\u30ea\u306b\u8aad\u307f\u8fbc\u3080<\/li>\n<\/ul>\n<p>\u3069\u3061\u3089\u306e\u30d1\u30bf\u30fc\u30f3\u3067\u52d5\u4f5c\u3057\u305f\u3068\u3057\u3066\u3082\u3001\u95a2\u9023\u4ed8\u3051\u3089\u308c\u305f2\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u30c7\u30fc\u30bf\u3092\u53c2\u7167\u3067\u304d\u307e\u3059\u306e\u3067\u3001\u3044\u3063\u305f\u3093\u8a66\u3057\u3066\u307f\u308b\u306e\u304c\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u30b3\u30fc\u30c9\u5b9f\u884c\u6642\u306b\u767a\u884c\u3055\u308c\u305fSQL\u306b\u3001<span style=\"color: #339966;\"><strong>\u300cLEFT OUTER JOIN\u300d<\/strong><\/span>\u3068\u8868\u793a\u3055\u308c\u3066\u3044\u308c\u3070\u5de6\u5916\u90e8\u7d50\u5408\u3092\u3057\u3066\u304a\u308a\u3001\u8868\u793a\u3055\u308c\u3066\u3044\u306a\u3051\u308c\u30702\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u305d\u306e\u307e\u307e\u30e1\u30e2\u30ea\u306b\u8aad\u307f\u8fbc\u3093\u3067\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >Post.includes(:user).each { |post| puts \"\u2605 post.id=#{post.id} : post.user.name=#{post.user.name}\" }<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  Post Load (0.1ms)  SELECT \"posts\".* FROM \"posts\"\r\n  User Load (0.3ms)  SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" IN (5, 1, 3, 4, 2)\r\n\u2605 post.id=1 : post.user.name=\u7d30\u5ddd\u4fee\u4e8c\r\n\u2605 post.id=2 : post.user.name=\u5c71\u7530\u592a\u90ce\r\n\u2605 post.id=3 : post.user.name=\u7acb\u5ddd\u88d5\u7f8e\r\n\u2605 post.id=4 : post.user.name=\u7acb\u5ddd\u88d5\u7f8e\r\n\u2605 post.id=5 : post.user.name=\u524d\u7530\u9054\u90ce\r\n\u2605 post.id=6 : post.user.name=\u9577\u702c\u6765\r\n\u2605 post.id=7 : post.user.name=\u524d\u7530\u9054\u90ce\r\n\u2605 post.id=8 : post.user.name=\u7acb\u5ddd\u88d5\u7f8e\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| id | user_id | title            | month | created_at      | updated_at       |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| 1  | 5       | \u697d\u3057\u3044\u4f11\u65e5\u306e...  | 3     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 2  | 1       | \u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71 | 2     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b     | 12    | 2018-06-21 1... | 2018-06-21 14... |\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d...  | 8     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 5  | 4       | \u53cb\u4eba\u304c\u7d50\u5a5a\u3057...  | 4     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 6  | 2       | \u6700\u8fd1\u5c11\u3057\u6c17\u306b...  | 1     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 7  | 4       | \u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4 | 9     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 8  | 3       | Ruby on Rails... | 9     | 2018-06-21 1... | 2018-06-21 14... |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n8 rows in set<\/pre>\n<p>\u524d\u8ff0\u306e2\u3064\u3068\u306f\u3060\u3044\u3076\u9055\u3046\u3053\u3068\u306b\u6c17\u304c\u3064\u3044\u305f\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>1\u756a\u306epost\u306e\u6295\u7a3f\u8005\u304c<span style=\"color: #0000ff;\"><strong>\u7d30\u5ddd\u4fee\u4e8c<\/strong><\/span>\u3055\u3093\u3067\u3042\u308b\u3053\u3068\u304c\u53d6\u5f97\u3067\u304d\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u304c\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u306f\u5168\u90e8\u30672\u56de\u3057\u304b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u304a\u3089\u305a\u3001\u898b\u4e8b\u306b<span style=\"color: #0000ff;\"><strong>N+1\u554f\u984c\u3092\u56de\u907f\u3057\u3066\u3044\u307e\u3059\u306d\uff01<\/strong><\/span><\/p>\n<h4>\u5de6\u5916\u90e8\u7d50\u5408\uff08LEFT OUTER JOIN\uff09\u3068\u306f<\/h4>\n<p><span style=\"color: #339966;\"><strong>\u5de6\u5916\u90e8\u7d50\u5408\uff08LEFT OUTER JOIN\uff09<\/strong><\/span>\u306f\u3001<span style=\"color: #0000ff\"><strong>1\u3064\u76ee\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u30ab\u30e9\u30e0\u3092\u512a\u5148\u3057\u30662\u3064\u76ee\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u7d50\u5408\u3059\u308b\u3001\u305d\u306e\u969b\u30012\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u3069\u3061\u3089\u304b\u306b\u3057\u304b\u5b58\u5728\u3057\u306a\u3044\u30c7\u30fc\u30bf\u3082\u542b\u3081\u308b<\/strong><\/span>\u3068\u3044\u3046\u610f\u5473\u3067\u3059\u3002<\/p>\n<p>\u5de6\u5916\u90e8\u7d50\u5408\uff08LEFT OUTER JOIN\uff09\u4ee5\u5916\u306b\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u7d50\u5408\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li><span style=\"color: #339966;\"><strong>\u53f3\u5916\u90e8\u7d50\u5408\uff08RIGHT OUTER JOIN\uff09<\/strong><\/span><\/li>\n<li><span style=\"color: #339966;\"><strong>\u5b8c\u5168\u5916\u90e8\u7d50\u5408\uff08FULL OUTER JOIN\uff09<\/strong><\/span><\/li>\n<li><span style=\"color: #339966;\"><strong>\u5185\u90e8\u7d50\u5408\uff08INNER JOIN\uff09<\/strong><\/span><\/li>\n<\/ul>\n<p>\u3061\u306a\u307f\u306b\u3001<span style=\"color: #339966;\"><strong>joins<\/strong><\/span>\u306f\u5185\u90e8\u7d50\u5408\uff08INNER JOIN\uff09\u3092\u884c\u3046\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u7d50\u5408\u65b9\u6cd5\u306b\u3064\u3044\u3066\u8a73\u3057\u304f\u8aac\u660e\u3059\u308b\u3068\u4e00\u3064\u306e\u8a18\u4e8b\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u8a18\u4e8b\u3092\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u53c2\u8003\uff1a<a href=\"http:\/\/qiita.com\/naoki_mochizuki\/items\/3fda1ad6594c11d7b43c\">Quiita SQL\u7d20\u4eba\u3067\u3082\u5206\u304b\u308b\u30c6\u30fc\u30d6\u30eb\u7d50\u5408(inner join\u3068outer join)<\/a><\/p>\n<h3>\u305d\u306e\u4ed6\u306e\u65b9\u6cd5<\/h3>\n<p>\u95a2\u9023\u4ed8\u3051\u3089\u308c\u305f2\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u30c7\u30fc\u30bf\u3092\u53c2\u7167\u3059\u308b\u65b9\u6cd5\u306f\u3001includes\u3092\u542b\u3081\u308b\u3068\u4ee5\u4e0b\u306e4\u3064\u304c\u6709\u540d\u3067\u3059\u3002<\/p>\n<ul>\n<li><span style=\"color: #339966\"><strong>joins<\/strong><\/span><\/li>\n<li><span style=\"color: #339966\"><strong>includes<\/strong><\/span><\/li>\n<li><span style=\"color: #339966\"><strong>preload<\/strong><\/span><\/li>\n<li><span style=\"color: #339966\"><strong>eager_load<\/strong><\/span><\/li>\n<\/ul>\n<p>\u3053\u306e\u3046\u3061joins\u306f<span style=\"color: #ff0000;\"><strong>N+1\u554f\u984c<\/strong><\/span>\u304c\u767a\u751f\u3057\u307e\u3059\u304c\u3001\u305d\u308c\u4ee5\u5916\u306fN+1\u554f\u984c\u304c\u767a\u751f\u3057\u307e\u305b\u3093\u3002<\/p>\n<p><span style=\"color: #339966;\"><strong>includes<\/strong><\/span>\u306f\u3001preload\u3068eager_load\u3092<span style=\"color: #0000ff;\"><strong>\u72b6\u6cc1\u306b\u5fdc\u3058\u3066\u81ea\u52d5\u7684\u306b\u4f7f\u3044\u5206\u3051\u308b\u30e1\u30bd\u30c3\u30c9<\/strong><\/span>\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u30c8\u30e9\u30d6\u30eb\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u306f\u3001preload\u3068eager_load\u306e\u52d5\u4f5c\u3092\u7406\u89e3\u3057\u3066\u3001\u3057\u3063\u304b\u308a\u4f7f\u3044\u5206\u3051\u308b\u65b9\u304c\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<h2>includes\u306b\u6761\u4ef6\u3092\u3064\u3051\u308b\uff08where\uff09<\/h2>\n<p><span style=\"color: #339966;\"><strong>includes<\/strong><\/span>\u3068<span style=\"color: #339966;\"><strong>where<\/strong><\/span>\u3092\u540c\u6642\u306b\u4f7f\u7528\u3059\u308b\u3068\u3001SQL\u306e\u767a\u884c\u56de\u6570\u3092\u5c11\u306a\u304f\u6291\u3048\u3064\u3064\u3001<span style=\"color: #0000ff;\"><strong>\u6761\u4ef6\u3092\u3064\u3051\u3089\u308c\u307e\u3059\u3002<\/strong><\/span><\/p>\n<p>Post\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u3068\u304d\u306b\u3001month=9\u306epost\u3060\u3051\u3092\u5bfe\u8c61\u306b\u3001\u30e6\u30fc\u30b6\u30fc\u540d\u3092\u53d6\u5f97\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\uff081\uff09Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u6b21\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"decode:true \" >Post.includes(:user).where(posts: {month: 9}).each { |post| puts \"\u2605 post.id=#{post.id} : post.user.name=#{post.user.name}\" }<\/pre>\n<p>\u5148\u307b\u3069\u306eincludes\u3092\u4f7f\u3063\u305f\u30b3\u30fc\u30c9\u3068\u6bd4\u8f03\u3059\u308b\u3068\u3001\u9014\u4e2d\u306b<span style=\"color: #339966;\"><strong>\u300c.where(posts: {month: 9})\u300d<\/strong><\/span>\u304c\u8ffd\u52a0\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u5b9f\u884c\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  Post Load (0.2ms)  SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"month\" = ?  [[\"month\", 9]]\r\n  User Load (0.1ms)  SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" IN (4, 3)\r\n\u2605 post.id=7 : post.user.name=\u524d\u7530\u9054\u90ce\r\n\u2605 post.id=8 : post.user.name=\u7acb\u5ddd\u88d5\u7f8e\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| id | user_id | title            | month | created_at      | updated_at       |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| 7  | 4       | \u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4 | 9     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 8  | 3       | Ruby on Rails... | 9     | 2018-06-21 1... | 2018-06-21 14... |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n2 rows in set<\/pre>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306e\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u52d5\u4f5c\u3057\u307e\u3059\u3002<\/p>\n<p>\u2460Post\u30c6\u30fc\u30d6\u30eb\u304b\u3089\uff08\u3059\u3079\u3066\u306epost\u3092\u53d6\u5f97\u3059\u308b\u306e\u3067\u306f\u306a\u304f\uff09<span style=\"color: #0000ff;\"><strong>month=9\u306epost\u3060\u3051\u3092\u53d6\u5f97<\/strong><\/span>\u3057\u3001\u53d6\u5f97\u3057\u305fpost\u306euser_id\uff08\u4eca\u56de\u306f4, 3\uff09\u3092\u4fdd\u6301\uff08\u30ad\u30e3\u30c3\u30b7\u30e5\uff09\u3059\u308b<\/p>\n<p>\u2461User\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u3001<span style=\"color: #0000ff;\"><strong>id = 4,  3\u306e\u30c7\u30fc\u30bf\u3060\u3051\u3092\u53d6\u5f97\u3059\u308b\u3002<\/strong><\/span><\/p>\n<p>\u2462\u53d6\u5f97\u3057\u305fuser\u30c7\u30fc\u30bf\u3092\u53c2\u7167\u3057\u3066\u3001post.user.name\u3092\u8868\u793a\u3059\u308b\u3002<\/p>\n<p>where\u3092\u8ffd\u52a0\u3057\u3066\u6761\u4ef6\u3092\u4ed8\u3051\u3066\u3082\u3001SQL\u3092\u767a\u884c\u3059\u308b\u306e\u306f\u2460\u3068\u2461\u306e2\u56de\u3060\u3051\u3067\u3059\u3002<\/p>\n<p>\uff082\uff09\u7d9a\u3051\u3066\u3001\u6b21\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"decode:true \" >Post.includes(:user).where(users: {name: \"\u7acb\u5ddd\u88d5\u7f8e\"}).each { |post| puts \"\u2605 post.id=#{post.id} : post.user.name=#{post.user.name}\" }<\/pre>\n<p>name=\"\u7acb\u5ddd\u88d5\u7f8e\"\u306eusers\u3060\u3051\u3092\u5bfe\u8c61\u306b\u3001\u30e6\u30fc\u30b6\u30fc\u540d\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n<p>\u5b9f\u884c\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  SQL (0.3ms)  SELECT \"posts\".\"id\" AS t0_r0, \"posts\".\"user_id\" AS t0_r1, \"posts\".\"title\" AS t0_r2, \"posts\".\"month\" AS t0_r3, \"posts\".\"created_at\" AS t0_r4, \"posts\".\"updated_at\" AS t0_r5, \"users\".\"id\" AS t1_r0, \"users\".\"name\" AS t1_r1, \"users\".\"created_at\" AS t1_r2, \"users\".\"updated_at\" AS t1_r3 FROM \"posts\" LEFT OUTER JOIN \"users\" ON \"users\".\"id\" = \"posts\".\"user_id\" WHERE \"users\".\"name\" = ?  [[\"name\", \"\u7acb\u5ddd\u88d5\u7f8e\"]]\r\n\u2605 post.id=3 : post.user.name=\u7acb\u5ddd\u88d5\u7f8e\r\n\u2605 post.id=4 : post.user.name=\u7acb\u5ddd\u88d5\u7f8e\r\n\u2605 post.id=8 : post.user.name=\u7acb\u5ddd\u88d5\u7f8e\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| id | user_id | title            | month | created_at      | updated_at       |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b     | 12    | 2018-06-21 1... | 2018-06-21 14... |\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d...  | 8     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 8  | 3       | Ruby on Rails... | 9     | 2018-06-21 1... | 2018-06-21 14... |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n3 rows in set<\/pre>\n<p>\u5148\u307b\u3069\u306eSQL\u6587\u3068\u306f\u307e\u3063\u305f\u304f\u7570\u306a\u308a\u307e\u3059\u304c\u3001\u671f\u5f85\u3059\u308b\u30c7\u30fc\u30bf\u304c\u53d6\u5f97\u3067\u304d\u3066\u3044\u307e\u3059\u306d\u3002<\/p>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306e\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u52d5\u4f5c\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u2460User\u30c6\u30fc\u30d6\u30eb\u306eid\u3068Post\u30c6\u30fc\u30d6\u30eb\u306euser_id\u3092\u5bfe\u5fdc\u3055\u305b\u308b\u65b9\u6cd5\u3067\u3001<span style=\"color: #0000ff;\"><strong>Post\u30c6\u30fc\u30d6\u30eb\u3068User\u30c6\u30fc\u30d6\u30eb\u3092\u5de6\u5916\u90e8\u7d50\u5408\uff08LEFT OUTER JOIN\uff09\u3059\u308b\u3002<\/strong><\/span><\/p>\n<p>\u2461\u5de6\u5916\u90e8\u7d50\u5408\u3057\u305f\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u3001users.name = \"\u7acb\u5ddd\u88d5\u7f8e\"\u306e\u30c7\u30fc\u30bf\u3060\u3051\u3092\u53d6\u5f97\u3059\u308b\u3002<\/p>\n<p>\u2462\u6700\u5f8c\u306b\u3001\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u3092\u53c2\u7167\u3057\u3066\u3001post.user.name\u3092\u8868\u793a\u3059\u308b\u3002<\/p>\n<p>\u2460\u3068\u2461\u3092\u307e\u3068\u3081\u3066\u30011\u56de\u306eSQL\u3067\u6e08\u307e\u305b\u3066\u3044\u307e\u3059\u306d\u3002<\/p>\n<h2>\u30cd\u30b9\u30c8\u3055\u308c\u305f\u8907\u6570\u306e\u30c6\u30fc\u30d6\u30eb\u304b\u3089includes\u3067\u30c7\u30fc\u30bf\u3092\u4e00\u62ec\u53d6\u5f97\u3059\u308b\u65b9\u6cd5<\/h2>\n<p>\u6700\u5f8c\u306b\u3001\u30cd\u30b9\u30c8\u3055\u308c\u305f\u8907\u6570\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u6271\u3063\u305f\u3068\u304d\u306b<span style=\"color: #ff0000;\"><strong>N+1\u554f\u984c<\/strong><\/span>\u304c\u767a\u751f\u3057\u306a\u3044\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\uff081\uff09\u6df7\u4e71\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u3001\u3059\u3067\u306b\u8d77\u52d5\u3057\u3066\u3044\u308bRails\u30b5\u30fc\u30d0\u30fc\u3092\u7d42\u4e86\u3057\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306b\u3001scaffold\u3067\u4f5c\u6210\u3057\u305f\u30c7\u30fc\u30bf\u3092\u3059\u3079\u3066\u524a\u9664\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\uff082\uff09\u65b0\u3057\u3044\u300c\u7aef\u672b\u300d\u3092\u8d77\u52d5\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u30921\u884c\u305a\u3064\u9806\u756a\u306b\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >cd app\/samurai\/includes-demo\r\nbin\/rails destroy scaffold user\r\nbin\/rails destroy scaffold posts\r\nbin\/rails db:drop DISABLE_DATABASE_ENVIRONMENT_CHECK=1<\/pre>\n<p>\uff083\uff09\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u30921\u884c\u305a\u3064\u9806\u756a\u306b\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >bin\/rails generate scaffold Team name\r\nbin\/rails generate scaffold User name:string team_id:integer\r\nbin\/rails generate scaffold Post user_id:integer title:string month:integer\r\nbin\/rails db:migrate\r\nbin\/rails server<\/pre>\n<p>\uff084\uff09\u65b0\u3057\u3044\u300c\u7aef\u672b\u300d\u3092\u8d77\u52d5\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u30921\u884c\u305a\u3064\u9806\u756a\u306b\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >cd app\/samurai\/includes-demo\r\nbin\/rails console<\/pre>\n<p>\uff085\uff09\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >Team.create(name: \"A\u30c1\u30fc\u30e0\")\r\nTeam.create(name: \"B\u30c1\u30fc\u30e0\")\r\nUser.create(name:\"\u5c71\u7530\u592a\u90ce\", team_id:1)\r\nUser.create(name:\"\u9577\u702c\u6765\", team_id:1)\r\nUser.create(name:\"\u7acb\u5ddd\u88d5\u7f8e\", team_id:2)\r\nUser.create(name:\"\u524d\u7530\u9054\u90ce\", team_id:2)\r\nUser.create(name:\"\u7d30\u5ddd\u4fee\u4e8c\", team_id:1)\r\nUser.create(name:\"\u6728\u6751\u62d3\u78e8\", team_id:1)\r\nPost.create(user_id:5,title:\"\u697d\u3057\u3044\u4f11\u65e5\u306e\u904e\u3054\u3057\u65b9\" ,month:3)\r\nPost.create(user_id:1,title:\"\u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71\" ,month:2)\r\nPost.create(user_id:3,title:\"\u6628\u65e5\u306e\u51fa\u6765\u4e8b\" ,month:12)\r\nPost.create(user_id:3,title:\"\u5c71\u767b\u308a\u306b\u884c\u304d\u307e\u3057\u305f\" ,month:8)\r\nPost.create(user_id:4,title:\"\u53cb\u4eba\u304c\u7d50\u5a5a\u3057\u307e\u3057\u305f\" ,month:4)\r\nPost.create(user_id:2,title:\"\u6700\u8fd1\u5c11\u3057\u6c17\u306b\u306a\u3063\u305f\u3053\u3068\" ,month:1)\r\nPost.create(user_id:4,title:\"\u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4\" ,month:9)\r\nPost.create(user_id:3,title:\"Ruby on Rails\u306e\u65e5\" ,month:9)\r\nexit<\/pre>\n<p>User\u30c6\u30fc\u30d6\u30eb\u3068Post\u30c6\u30fc\u30d6\u30eb\u306b\u30c7\u30fc\u30bf\u304c\u5165\u529b\u3055\u308c\u3001Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u304c\u7d42\u4e86\u3057\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306bTeam\u30c6\u30fc\u30d6\u30eb\u3068User\u30c6\u30fc\u30d6\u30eb\u3001Post\u30c6\u30fc\u30d6\u30eb\u3092\u95a2\u9023\u4ed8\u3051\u307e\u3059\u3002<\/p>\n<p>\uff084\uff09<span style=\"color: #339966;\"><strong>app\/models\/team.rb<\/strong><\/span>\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7de8\u96c6\u3057\u307e\u3059\u3002<\/p>\n<p>\u5909\u66f4\u524d\uff1a<\/p>\n<pre class=\"decode:true \" >class Team < ApplicationRecord\r\nend<\/pre>\n<p>\u5909\u66f4\u5f8c\uff1a<\/p>\n<pre class=\"decode:true \" >class Team < ApplicationRecord\r\n  has_many :users\r\nend<\/pre>\n<p>\uff085\uff09<span style=\"color: #339966;\"><strong>app\/models\/user.rb<\/strong><\/span>\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7de8\u96c6\u3057\u307e\u3059\u3002<\/p>\n<p>\u5909\u66f4\u524d\uff1a<\/p>\n<pre class=\"decode:true \" >class User < ApplicationRecord\r\nend<\/pre>\n<p>\u5909\u66f4\u5f8c\uff1a<\/p>\n<pre class=\"decode:true \" >class User < ApplicationRecord\r\n  has_many :posts\r\n  belongs_to :team\r\nend<\/pre>\n<p>\uff086\uff09<span style=\"color: #339966;\"><strong>app\/models\/post.rb<\/strong><\/span>\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7de8\u96c6\u3057\u307e\u3059\u3002<\/p>\n<p>\u5909\u66f4\u524d\uff1a<\/p>\n<pre class=\"decode:true \" >class Post < ApplicationRecord\r\nend<\/pre>\n<p>\u5909\u66f4\u5f8c\uff1a<\/p>\n<pre class=\"decode:true \" >class Post < ApplicationRecord\r\n  belongs_to :user\r\nend<\/pre>\n<p>\u3053\u308c\u3067\u3001\u30c7\u30fc\u30bf\u306e\u6e96\u5099\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\uff087\uff09\u65b0\u3057\u3044<span style=\"color: #339966;\"><strong>\u300c\u7aef\u672b\u300d<\/strong><\/span>\u3092\u8d77\u52d5\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u30921\u884c\u305a\u3064\u9806\u756a\u306b\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >cd app\/samurai\/includes-demo\r\nbin\/rails console\r\nHirb.enable<\/pre>\n<p>\uff088\uff09\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >Post.all.each { |post| puts \"\u2605 post.id=#{post.id} : post.user.team.name=#{post.user.team.name}\" }<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" > Post Load (0.1ms)  SELECT \"posts\".* FROM \"posts\"\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 5], [\"LIMIT\", 1]]\r\n  Team Load (0.1ms)  SELECT  \"teams\".* FROM \"teams\" WHERE \"teams\".\"id\" = ? LIMIT ?  [[\"id\", 1], [\"LIMIT\", 1]]\r\n\u2605 post.id=1 : post.user.team.name=A\u30c1\u30fc\u30e0\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 1], [\"LIMIT\", 1]]\r\n  Team Load (0.1ms)  SELECT  \"teams\".* FROM \"teams\" WHERE \"teams\".\"id\" = ? LIMIT ?  [[\"id\", 1], [\"LIMIT\", 1]]\r\n\u2605 post.id=2 : post.user.team.name=A\u30c1\u30fc\u30e0\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 3], [\"LIMIT\", 1]]\r\n  Team Load (0.1ms)  SELECT  \"teams\".* FROM \"teams\" WHERE \"teams\".\"id\" = ? LIMIT ?  [[\"id\", 2], [\"LIMIT\", 1]]\r\n\u2605 post.id=3 : post.user.team.name=B\u30c1\u30fc\u30e0\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 3], [\"LIMIT\", 1]]\r\n  Team Load (0.1ms)  SELECT  \"teams\".* FROM \"teams\" WHERE \"teams\".\"id\" = ? LIMIT ?  [[\"id\", 2], [\"LIMIT\", 1]]\r\n\u2605 post.id=4 : post.user.team.name=B\u30c1\u30fc\u30e0\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 4], [\"LIMIT\", 1]]\r\n  Team Load (0.1ms)  SELECT  \"teams\".* FROM \"teams\" WHERE \"teams\".\"id\" = ? LIMIT ?  [[\"id\", 2], [\"LIMIT\", 1]]\r\n\u2605 post.id=5 : post.user.team.name=B\u30c1\u30fc\u30e0\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 2], [\"LIMIT\", 1]]\r\n  Team Load (0.1ms)  SELECT  \"teams\".* FROM \"teams\" WHERE \"teams\".\"id\" = ? LIMIT ?  [[\"id\", 1], [\"LIMIT\", 1]]\r\n\u2605 post.id=6 : post.user.team.name=A\u30c1\u30fc\u30e0\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 4], [\"LIMIT\", 1]]\r\n  Team Load (0.1ms)  SELECT  \"teams\".* FROM \"teams\" WHERE \"teams\".\"id\" = ? LIMIT ?  [[\"id\", 2], [\"LIMIT\", 1]]\r\n\u2605 post.id=7 : post.user.team.name=B\u30c1\u30fc\u30e0\r\n  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 3], [\"LIMIT\", 1]]\r\n  Team Load (0.1ms)  SELECT  \"teams\".* FROM \"teams\" WHERE \"teams\".\"id\" = ? LIMIT ?  [[\"id\", 2], [\"LIMIT\", 1]]\r\n\u2605 post.id=8 : post.user.team.name=B\u30c1\u30fc\u30e0\r\n+----+---------+------------------------+-------+-------------------------+-------------------------+\r\n| id | user_id | title                  | month | created_at              | updated_at              |\r\n+----+---------+------------------------+-------+-------------------------+-------------------------+\r\n| 1  | 5       | \u697d\u3057\u3044\u4f11\u65e5\u306e\u904e\u3054\u3057\u65b9   | 3     | 2018-06-21 15:26:39 UTC | 2018-06-21 15:26:39 UTC |\r\n| 2  | 1       | \u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71       | 2     | 2018-06-21 15:26:39 UTC | 2018-06-21 15:26:39 UTC |\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b           | 12    | 2018-06-21 15:26:39 UTC | 2018-06-21 15:26:39 UTC |\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d\u307e\u3057\u305f     | 8     | 2018-06-21 15:26:39 UTC | 2018-06-21 15:26:39 UTC |\r\n| 5  | 4       | \u53cb\u4eba\u304c\u7d50\u5a5a\u3057\u307e\u3057\u305f     | 4     | 2018-06-21 15:26:39 UTC | 2018-06-21 15:26:39 UTC |\r\n| 6  | 2       | \u6700\u8fd1\u5c11\u3057\u6c17\u306b\u306a\u3063\u305f\u3053\u3068 | 1     | 2018-06-21 15:26:39 UTC | 2018-06-21 15:26:39 UTC |\r\n| 7  | 4       | \u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4       | 9     | 2018-06-21 15:26:39 UTC | 2018-06-21 15:26:39 UTC |\r\n| 8  | 3       | Ruby on Rails\u306e\u65e5      | 9     | 2018-06-21 15:26:39 UTC | 2018-06-21 15:26:39 UTC |\r\n+----+---------+------------------------+-------+-------------------------+-------------------------+\r\n8 rows in set<\/pre>\n<p>\u898b\u4e8b\u306a<span style=\"color: #ff0000;\"><strong>\u591a\u6bb5N+1\u554f\u984c<\/strong><\/span>\u3068\u3067\u3082\u8a00\u3048\u308b\u307b\u3069\u3001SQL\u304c\u767a\u884c\u3055\u308c\u3066\u3044\u307e\u3059\u306d\u3002<\/p>\n<p>\uff089\uff09\u6b21\u306f\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >Post.includes(user: :team).each { |post| puts \"\u2605 post.id=#{post.id} : post.user.team.name=#{post.user.team.name}\" }<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  Post Load (0.1ms)  SELECT \"posts\".* FROM \"posts\"\r\n  User Load (0.2ms)  SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" IN (5, 1, 3, 4, 2)\r\n  Team Load (0.3ms)  SELECT \"teams\".* FROM \"teams\" WHERE \"teams\".\"id\" IN (1, 2)\r\n\u2605 post.id=1 : post.user.team.name=A\u30c1\u30fc\u30e0\r\n\u2605 post.id=2 : post.user.team.name=A\u30c1\u30fc\u30e0\r\n\u2605 post.id=3 : post.user.team.name=B\u30c1\u30fc\u30e0\r\n\u2605 post.id=4 : post.user.team.name=B\u30c1\u30fc\u30e0\r\n\u2605 post.id=5 : post.user.team.name=B\u30c1\u30fc\u30e0\r\n\u2605 post.id=6 : post.user.team.name=A\u30c1\u30fc\u30e0\r\n\u2605 post.id=7 : post.user.team.name=B\u30c1\u30fc\u30e0\r\n\u2605 post.id=8 : post.user.team.name=B\u30c1\u30fc\u30e0\r\n+----+---------+------------------------+-------+-------------------------+-------------------------+\r\n| id | user_id | title                  | month | created_at              | updated_at              |\r\n+----+---------+------------------------+-------+-------------------------+-------------------------+\r\n| 1  | 5       | \u697d\u3057\u3044\u4f11\u65e5\u306e\u904e\u3054\u3057\u65b9   | 3     | 2018-06-21 15:26:39 UTC | 2018-06-21 15:26:39 UTC |\r\n| 2  | 1       | \u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71       | 2     | 2018-06-21 15:26:39 UTC | 2018-06-21 15:26:39 UTC |\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b           | 12    | 2018-06-21 15:26:39 UTC | 2018-06-21 15:26:39 UTC |\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d\u307e\u3057\u305f     | 8     | 2018-06-21 15:26:39 UTC | 2018-06-21 15:26:39 UTC |\r\n| 5  | 4       | \u53cb\u4eba\u304c\u7d50\u5a5a\u3057\u307e\u3057\u305f     | 4     | 2018-06-21 15:26:39 UTC | 2018-06-21 15:26:39 UTC |\r\n| 6  | 2       | \u6700\u8fd1\u5c11\u3057\u6c17\u306b\u306a\u3063\u305f\u3053\u3068 | 1     | 2018-06-21 15:26:39 UTC | 2018-06-21 15:26:39 UTC |\r\n| 7  | 4       | \u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4       | 9     | 2018-06-21 15:26:39 UTC | 2018-06-21 15:26:39 UTC |\r\n| 8  | 3       | Ruby on Rails\u306e\u65e5      | 9     | 2018-06-21 15:26:39 UTC | 2018-06-21 15:26:39 UTC |\r\n+----+---------+------------------------+-------+-------------------------+-------------------------+\r\n8 rows in set<\/pre>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306a\u3089<span style=\"color: #0000ff;\"><strong>\u591a\u6bb5N+1\u554f\u984c\u3092\u56de\u907f\u3067\u304d\u307e\u3059\u306d\uff01<\/strong><\/span><\/p>\n<h2>\u30c7\u30fc\u30bf\u3092\u4e26\u3079\u66ff\u3048\u308b\uff08order\uff09<\/h2>\n<p>\u3053\u3053\u307e\u3067\u3067\u3001\u52b9\u7387\u826f\u304f\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u51fa\u3059\u65b9\u6cd5\u3092\u8aac\u660e\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u306e\u6700\u5f8c\u3067\u306f\u3001\u3053\u3053\u307e\u3067\u8aac\u660e\u3057\u3066\u304d\u305fincludes\u3092\u4f7f\u3063\u3066\u52b9\u7387\u826f\u304f\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u51fa\u3057\u3001\u3053\u308c\u304b\u3089\u8aac\u660e\u3059\u308border\u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u3092\u4e26\u3079\u66ff\u3048\u308b\u3068\u3044\u3046\u5408\u308f\u305b\u6280\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u6e96\u5099\u6bb5\u968e\u3068\u3057\u3066\u3001<span style=\"color: #254df2;\"><strong>order\u306e\u4f7f\u3044\u65b9\u3092\u8aac\u660e\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/strong><\/span><\/p>\n<p>\u307e\u305a\u306f\u3001\u57fa\u672c\u7684\u306a\u65b9\u6cd5\u304b\u3089\u59cb\u3081\u307e\u3059\u3002<\/p>\n<p>\uff081\uff09Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >Post.order(:month)<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  Post Load (0.2ms)  SELECT \"posts\".* FROM \"posts\" ORDER BY \"posts\".\"month\" ASC\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| id | user_id | title            | month | created_at      | updated_at       |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| 6  | 2       | \u6700\u8fd1\u5c11\u3057\u6c17\u306b...  | 1     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 2  | 1       | \u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71 | 2     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 1  | 5       | \u697d\u3057\u3044\u4f11\u65e5\u306e...  | 3     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 5  | 4       | \u53cb\u4eba\u304c\u7d50\u5a5a\u3057...  | 4     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d...  | 8     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 7  | 4       | \u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4 | 9     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 8  | 3       | Ruby on Rails... | 9     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b     | 12    | 2018-06-21 1... | 2018-06-21 16... |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n8 rows in set<\/pre>\n<p>month\u304c<span style=\"color: #54a870;\"><strong>\u6607\u9806\uff08asc\uff1aascending order\uff09<\/strong><\/span>\u306b\u4e26\u3093\u3067\u3044\u307e\u3059\u306d\u3002<\/p>\n<p>\u6b21\u306f<span style=\"color: #54a870;\"><strong>\u964d\u9806\uff08desc\uff1adescending order\uff09<\/strong><\/span>\u306b\u4e26\u3079\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\uff082\uff09Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >Post.order(month: :desc)<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  Post Load (0.1ms)  SELECT \"posts\".* FROM \"posts\" ORDER BY \"posts\".\"month\" DESC\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| id | user_id | title            | month | created_at      | updated_at       |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b     | 12    | 2018-06-21 1... | 2018-06-21 16... |\r\n| 7  | 4       | \u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4 | 9     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 8  | 3       | Ruby on Rails... | 9     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d...  | 8     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 5  | 4       | \u53cb\u4eba\u304c\u7d50\u5a5a\u3057...  | 4     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 1  | 5       | \u697d\u3057\u3044\u4f11\u65e5\u306e...  | 3     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 2  | 1       | \u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71 | 2     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 6  | 2       | \u6700\u8fd1\u5c11\u3057\u6c17\u306b...  | 1     | 2018-06-21 1... | 2018-06-21 16... |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n8 rows in set<\/pre>\n<p>\u3061\u306a\u307f\u306b\u3001Post.order(month: :desc)\u306f\u3001\u4ee5\u4e0b\u306e\u3069\u306e\u66f8\u304d\u304b\u305f\u3067\u3082\u540c\u3058\u7d50\u679c\u304c\u5f97\u3089\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >Post.order(month: :desc)\r\nPost.order(month: \"desc\")\r\nPost.order(:month => :desc)\r\nPost.order(\"month desc\")<\/pre>\n<h3>\u8907\u6570\u306e\u30ab\u30e9\u30e0\u3092\u4f7f\u3063\u3066\u4e26\u3079\u66ff\u3048\u308b<\/h3>\n<p>\u6b21\u306f<span style=\"color: #254df2;\"><strong>\u8907\u6570\u306e\u30ab\u30e9\u30e0\u3092\u6761\u4ef6\u306b\u3059\u308b\u65b9\u6cd5<\/strong><\/span>\u3067\u3059\u3002<\/p>\n<p>\u5148\u307b\u3069\u306ePost\u30c6\u30fc\u30d6\u30eb\u3092\u3001<span style=\"color: #54a870;\"><strong>user_id<\/strong><\/span>\u9806\u306b\u3001user_id\u304c\u540c\u3058\u5834\u5408\u306f<span style=\"color: #54a870;\"><strong>month<\/strong><\/span>\u9806\u306b\u4e26\u3079\u66ff\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u306f\u3001user_id\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u30b3\u30fc\u30c9\u304b\u3089\u3067\u3059\u304c\u3001\u3053\u308c\u306f\u4e0a\u3067\u8aac\u660e\u3057\u305f\u30b3\u30fc\u30c9\u306emonth\u3092user_id\u306b\u5909\u3048\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<p>\uff081\uff09Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >Post.order(:user_id)<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  Post Load (0.2ms)  SELECT \"posts\".* FROM \"posts\" ORDER BY \"posts\".\"user_id\" ASC\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| id | user_id | title            | month | created_at      | updated_at       |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| 2  | 1       | \u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71 | 2     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 6  | 2       | \u6700\u8fd1\u5c11\u3057\u6c17\u306b...  | 1     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b     | 12    | 2018-06-21 1... | 2018-06-21 16... |\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d...  | 8     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 8  | 3       | Ruby on Rails... | 9     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 5  | 4       | \u53cb\u4eba\u304c\u7d50\u5a5a\u3057...  | 4     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 7  | 4       | \u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4 | 9     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 1  | 5       | \u697d\u3057\u3044\u4f11\u65e5\u306e...  | 3     | 2018-06-21 1... | 2018-06-21 16... |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n8 rows in set<\/pre>\n<p>user_id\u304c3\u306e\u30c7\u30fc\u30bf\u306emonth\u306b\u6ce8\u76ee\u3059\u308b\u3068\u300112, 8, 9\u306e\u9806\u306b\u4e26\u3093\u3067\u3044\u307e\u3059\u306d\u3002<\/p>\n<p>\u3053\u308c\u3092month\u9806\u306b\u4e26\u3079\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\uff082\uff09Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >Post.order(:user_id, :month)<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  Post Load (0.1ms)  SELECT \"posts\".* FROM \"posts\" ORDER BY \"posts\".\"user_id\" ASC, \"posts\".\"month\" ASC\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| id | user_id | title            | month | created_at      | updated_at       |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| 2  | 1       | \u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71 | 2     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 6  | 2       | \u6700\u8fd1\u5c11\u3057\u6c17\u306b...  | 1     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d...  | 8     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 8  | 3       | Ruby on Rails... | 9     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b     | 12    | 2018-06-21 1... | 2018-06-21 16... |\r\n| 5  | 4       | \u53cb\u4eba\u304c\u7d50\u5a5a\u3057...  | 4     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 7  | 4       | \u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4 | 9     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 1  | 5       | \u697d\u3057\u3044\u4f11\u65e5\u306e...  | 3     | 2018-06-21 1... | 2018-06-21 16... |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n8 rows in set<\/pre>\n<p>month\u3092\u964d\u9806\u306b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\uff083\uff09Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >Post.order(:user_id, month: :desc)<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  Post Load (0.2ms)  SELECT \"posts\".* FROM \"posts\" ORDER BY \"posts\".\"user_id\" ASC, \"posts\".\"month\" DESC\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| id | user_id | title            | month | created_at      | updated_at       |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| 2  | 1       | \u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71 | 2     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 6  | 2       | \u6700\u8fd1\u5c11\u3057\u6c17\u306b...  | 1     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b     | 12    | 2018-06-21 1... | 2018-06-21 16... |\r\n| 8  | 3       | Ruby on Rails... | 9     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d...  | 8     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 7  | 4       | \u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4 | 9     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 5  | 4       | \u53cb\u4eba\u304c\u7d50\u5a5a\u3057...  | 4     | 2018-06-21 1... | 2018-06-21 16... |\r\n| 1  | 5       | \u697d\u3057\u3044\u4f11\u65e5\u306e...  | 3     | 2018-06-21 1... | 2018-06-21 16... |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n8 rows in set<\/pre>\n<p>\u3061\u306a\u307f\u306b\u3001Post.order(:user_id, month: :desc)\u306f\u3001\u4ee5\u4e0b\u306e\u3069\u306e\u66f8\u304d\u304b\u305f\u3067\u3082\u540c\u3058\u7d50\u679c\u304c\u5f97\u3089\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >Post.order(:user_id, month: :desc)\r\nPost.order(:user_id, month: \"desc\")\r\nPost.order(:user_id, :month => :desc)\r\nPost.order(:user_id, \"month desc\")\r\nPost.order(:user_id).order(month: :desc)\r\nPost.order(:user_id).order(month: \"desc\")\r\nPost.order(:user_id).order(:month => :desc)\r\nPost.order(:user_id).order(\"month desc\")<\/pre>\n<h3>\u8a2d\u5b9a\u6e08\u307f\u306eorder\u3092\u4e0a\u66f8\u304d\u3059\u308b\uff08reorder\uff09<\/h3>\n<p>order\u306e\u66f8\u304d\u304b\u305f\u3092\u63a2\u3057\u3066\u3044\u308b\u3068<span style=\"color: #54a870;\"><strong>reorder<\/strong><\/span>\u306e\u8aac\u660e\u3082\u898b\u3064\u304b\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305f\u3060\u3001\u307b\u3068\u3093\u3069\u306e\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3067<span style=\"color: #f75959;\"><strong>order\u306e\u76f4\u5f8c\u306breorder\u3057\u3066\u3044\u3066\u3001\u4f7f\u3044\u3069\u3053\u308d\u304c\u3042\u308b\u306e!?<\/strong><\/span>\u3068\u3044\u3046\u6c17\u304c\u3057\u307e\u3059\u3002<\/p>\n<p>\u3067\u3082\u3001\u3061\u3083\u3093\u3068\u4f7f\u3044\u3069\u3053\u308d\u304c\u3042\u308b\u3093\u3067\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001reorder\u306f<span style=\"color: #54a870;\"><strong>deprecated\uff08\u5ec3\u6b62\u4e88\u5b9a\u3001\u975e\u63a8\u5968\uff09<\/strong><\/span>\u306b\u306a\u3063\u305f\u6642\u671f\u3082\u3042\u308a\u307e\u3057\u305f\u304c\u3001<span style=\"color: #254df2;\"><strong>\u73fe\u5728\u306fdeprecated\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u306e\u3067\u3001\u5802\u3005\u3068\u4f7f\u3044\u307e\u3057\u3087\u3046\u3002<\/strong><\/span><\/p>\n<p>\uff081\uff09Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3092\u7d42\u4e86\u3057\u307e\u3059\u3002<\/p>\n<p>\uff082\uff09<span style=\"color: #54a870;\"><strong>app\/models\/user.rb<\/strong><\/span>\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7de8\u96c6\u3057\u307e\u3059\u3002<\/p>\n<p>\u5909\u66f4\u524d\uff1a<\/p>\n<pre class=\"decode:true \" >class User < ApplicationRecord\r\n  has_many :posts\r\nend<\/pre>\n<p>\u5909\u66f4\u5f8c\uff1a<\/p>\n<pre class=\"decode:true \" >class User < ApplicationRecord\r\n  has_many :posts, -> {order(\"month asc\")}\r\nend<\/pre>\n<p>\u3053\u306e\u5909\u66f4\u3067\u3001User.find(3).posts\u306e\u3088\u3046\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3068\u304d\u306b\u3001posts\u3092month\u9806\u306b\u53d6\u5f97\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\uff083\uff09\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u30921\u884c\u305a\u3064\u9806\u756a\u306b\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >bin\/rails console\r\nHirb.enable\r\nUser.find(3).posts<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 3], [\"LIMIT\", 1]]\r\n  Post Load (0.2ms)  SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"user_id\" = ? ORDER BY month asc  [[\"user_id\", 3]]\r\n+----+---------+--------------------+-------+-------------------------+-------------------------+\r\n| id | user_id | title              | month | created_at              | updated_at              |\r\n+----+---------+--------------------+-------+-------------------------+-------------------------+\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d\u307e\u3057\u305f | 8     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 8  | 3       | Ruby on Rails\u306e\u65e5  | 9     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b       | 12    | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n+----+---------+--------------------+-------+-------------------------+-------------------------+\r\n3 rows in set<\/pre>\n<p>\u624b\u9806\uff082\uff09\u3067\u6307\u5b9a\u3057\u305f\u3068\u304a\u308a\u3001month\u9806\u306b\u53d6\u5f97\u3067\u304d\u3066\u3044\u307e\u3059\u306d\u3002<\/p>\n<p>\u3067\u306f\u3001month\u3092\u9006\u9806\u306b\u4e26\u3079\u66ff\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u306f\u3001\u3053\u3053\u307e\u3067\u3068\u5909\u308f\u3089\u305aorder\u3092\u4f7f\u3063\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\uff084\uff09Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >User.find(3).posts.order(month: :desc)<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  User Load (0.1ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 3], [\"LIMIT\", 1]]\r\n  Post Load (0.1ms)  SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"user_id\" = ? ORDER BY month asc, \"posts\".\"month\" DESC  [[\"user_id\", 3]]\r\n+----+---------+--------------------+-------+-------------------------+-------------------------+\r\n| id | user_id | title              | month | created_at              | updated_at              |\r\n+----+---------+--------------------+-------+-------------------------+-------------------------+\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d\u307e\u3057\u305f | 8     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 8  | 3       | Ruby on Rails\u306e\u65e5  | 9     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b       | 12    | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n+----+---------+--------------------+-------+-------------------------+-------------------------+\r\n3 rows in set<\/pre>\n<p>SQL\u3082\u5909\u308f\u3063\u3066\u3044\u307e\u3059\u304c\u3001<span style=\"color: #f75959;\"><strong>\u6b8b\u5ff5\u306a\u304c\u3089\u9006\u9806\u306b\u306a\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/strong><\/span><\/p>\n<p>\u3053\u3053\u3067<span style=\"color: #254df2;\"><strong>reorder\u3092\u4f7f\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/strong><\/span><\/p>\n<p>\uff085\uff09Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >User.find(3).posts.reorder(month: :desc)<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  User Load (0.2ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ?  [[\"id\", 3], [\"LIMIT\", 1]]\r\n  Post Load (0.1ms)  SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"user_id\" = ? ORDER BY \"posts\".\"month\" DESC  [[\"user_id\", 3]]\r\n+----+---------+--------------------+-------+-------------------------+-------------------------+\r\n| id | user_id | title              | month | created_at              | updated_at              |\r\n+----+---------+--------------------+-------+-------------------------+-------------------------+\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b       | 12    | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 8  | 3       | Ruby on Rails\u306e\u65e5  | 9     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d\u307e\u3057\u305f | 8     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n+----+---------+--------------------+-------+-------------------------+-------------------------+\r\n3 rows in set<\/pre>\n<p>SQL\u6587\u3082\u5909\u308f\u308a\u3001<span style=\"color: #ff0000; background-color: #ffff99;\"><strong>\u610f\u56f3\u3057\u305f\u3068\u304a\u308a\u9006\u9806\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u306d\uff01<\/strong><\/span><\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u3001\u3042\u3089\u304b\u3058\u3081\u9806\u756a\u304c\u6307\u5b9a\u3055\u308c\u3066\u3044\u308b\u30c7\u30fc\u30bf\u3092\u3001\u5225\u306e\u65b9\u6cd5\u3067\u4e26\u3079\u66ff\u3048\u308b\u3068\u304d\u306freorder\u3092\u4f7f\u3046\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u3059\u3002<\/p>\n<h3>\u9806\u756a\u30921\u30641\u3064\u6307\u5b9a\u3057\u3066\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\uff08order_as_specified gem\uff09<\/h3>\n<p><span style=\"color: #54a870;\"><strong>order_as_specified gem<\/strong><\/span>\u3092\u4f7f\u3063\u3066\u3001<span style=\"color: #254df2;\"><strong>\u9806\u756a\u30921\u30641\u3064\u6307\u5b9a\u3057\u3066\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5<\/strong><\/span>\u3092\u7d39\u4ecb\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u53c2\u8003\uff1a<a href=\"https:\/\/github.com\/panorama-ed\/order_as_specified\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/panorama-ed\/order_as_specified<\/a><\/p>\n<h4>order_as_specified gem\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/h3>\n<p>\u9806\u756a\u30921\u30641\u3064\u6307\u5b9a\u3057\u3066\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306b\u3001order_as_specified gem\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\uff081\uff09<span style=\"color: #339966;\"><strong>Gemfile<\/strong><\/span>\u306e\u6700\u7d42\u884c\u306b\u4ee5\u4e0b\u306e\u5185\u5bb9\u3092\u8ffd\u8a18\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >gem 'order_as_specified'<\/pre>\n<p>\uff082\uff09\u65b0\u3057\u3044<span style=\"color: #339966;\"><strong>\u300c\u7aef\u672b\u300d<\/strong><\/span>\u3092\u8d77\u52d5\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u30921\u884c\u305a\u3064\u9806\u756a\u306b\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >cd app\/samurai\/includes-demo\r\nbundle install<\/pre>\n<p>\u3053\u308c\u3067\u3001<span style=\"color: #339966;\"><strong>order_as_specified gem<\/strong><\/span>\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<h4>\u9806\u756a\u30921\u30641\u3064\u6307\u5b9a\u3057\u3066\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b<\/h4>\n<p>\u3067\u306f\u3001\u9806\u756a\u3092\u6307\u5b9a\u3057\u3066\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u3053\u3053\u3067\u306f\u3001Post\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u3001<span style=\"color: #254df2;\"><strong>user_id\u304c\u300c1\u30013\u30015\u30012\u30014\u300d\u306e\u9806\u756a\u306b\u306a\u308b\u3088\u3046\u306b\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3066\u307f\u307e\u3059\u3002<\/strong><\/span><\/p>\n<p>\uff081\uff09Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3092\u7d42\u4e86\u3057\u307e\u3059\u3002<\/p>\n<p>\uff082\uff09<span style=\"color: #54a870;\"><strong>app\/models\/post.rb<\/strong><\/span>\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7de8\u96c6\u3057\u307e\u3059\u3002<\/p>\n<p>\u5909\u66f4\u524d\uff1a<\/p>\n<pre class=\"decode:true \" >class Post < ApplicationRecord\r\n  belongs_to :user\r\nend<\/pre>\n<p>\u5909\u66f4\u5f8c\uff1a<\/p>\n<pre class=\"decode:true \" >class Post < ApplicationRecord\r\n  extend OrderAsSpecified\r\n  belongs_to :user\r\nend<\/pre>\n<p>\uff083\uff09\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u30921\u884c\u305a\u3064\u9806\u756a\u306b\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >bin\/rails console\r\nHirb.enable\r\nPost.order_as_specified(user_id: [1,3,5,2,4])<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  Post Load (0.3ms)  SELECT \"posts\".* FROM \"posts\" ORDER BY \"posts\".\"user_id\"=1 DESC, \"posts\".\"user_id\"=3 DESC, \"posts\".\"user_id\"=5 DESC, \"posts\".\"user_id\"=2 DESC, \"posts\".\"user_id\"=4 DESC\r\n+----+---------+------------------------+-------+-------------------------+-------------------------+\r\n| id | user_id | title                  | month | created_at              | updated_at              |\r\n+----+---------+------------------------+-------+-------------------------+-------------------------+\r\n| 2  | 1       | \u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71       | 2     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b           | 12    | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d\u307e\u3057\u305f     | 8     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 8  | 3       | Ruby on Rails\u306e\u65e5      | 9     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 1  | 5       | \u697d\u3057\u3044\u4f11\u65e5\u306e\u904e\u3054\u3057\u65b9   | 3     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 6  | 2       | \u6700\u8fd1\u5c11\u3057\u6c17\u306b\u306a\u3063\u305f\u3053\u3068 | 1     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 5  | 4       | \u53cb\u4eba\u304c\u7d50\u5a5a\u3057\u307e\u3057\u305f     | 4     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 7  | 4       | \u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4       | 9     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n+----+---------+------------------------+-------+-------------------------+-------------------------+\r\n8 rows in set<\/pre>\n<p>user_id\u306b\u6ce8\u76ee\u3059\u308b\u3068\u3001\u300c1\u30013\u30015\u30012\u30014\u300d\u306e\u9806\u756a\u3067\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3067\u304d\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092\u3055\u3089\u306b\u3001month\u9806\u306b\u4e26\u3079\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\uff085\uff09Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >Post.order_as_specified(user_id: [1,3,5,2,4]).order(:month)<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  Post Load (0.3ms)  SELECT \"posts\".* FROM \"posts\" ORDER BY \"posts\".\"user_id\"=1 DESC, \"posts\".\"user_id\"=3 DESC, \"posts\".\"user_id\"=5 DESC, \"posts\".\"user_id\"=2 DESC, \"posts\".\"user_id\"=4 DESC, \"posts\".\"month\" ASC\r\n+----+---------+------------------------+-------+-------------------------+-------------------------+\r\n| id | user_id | title                  | month | created_at              | updated_at              |\r\n+----+---------+------------------------+-------+-------------------------+-------------------------+\r\n| 2  | 1       | \u5148\u65e5\u306e\u65c5\u884c\u3067\u306e\u8a71       | 2     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d\u307e\u3057\u305f     | 8     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 8  | 3       | Ruby on Rails\u306e\u65e5      | 9     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b           | 12    | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 1  | 5       | \u697d\u3057\u3044\u4f11\u65e5\u306e\u904e\u3054\u3057\u65b9   | 3     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 6  | 2       | \u6700\u8fd1\u5c11\u3057\u6c17\u306b\u306a\u3063\u305f\u3053\u3068 | 1     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 5  | 4       | \u53cb\u4eba\u304c\u7d50\u5a5a\u3057\u307e\u3057\u305f     | 4     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n| 7  | 4       | \u30e9\u30f3\u30cb\u30f3\u30b0\u306e\u30b3\u30c4       | 9     | 2018-06-21 16:20:39 UTC | 2018-06-21 16:20:39 UTC |\r\n+----+---------+------------------------+-------+-------------------------+-------------------------+\r\n8 rows in set<\/pre>\n<p>\u7d20\u6674\u3089\u3057\u3044\u3067\u3059\u306d\uff01<\/p>\n<h2>includes\u306e\u7d50\u679c\u3092\u4e26\u3079\u66ff\u3048\u308b\uff08includes\u3001order\uff09<\/h2>\n<p>\u3053\u3053\u307e\u3067\u3067\u3001includes\u3068order\u306e\u4f7f\u3044\u65b9\u3092\u5225\u3005\u306b\u78ba\u8a8d\u3057\u307e\u3057\u305f\u306e\u3067\u3001\u6700\u5f8c\u306b\u3001<span style=\"color: #254df2;\"><strong>includes\u3068order\u3092\u540c\u6642\u306b\u4f7f\u3046\u30b1\u30fc\u30b9\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/strong><\/span><\/p>\n<p>Post\u30c6\u30fc\u30d6\u30eb\u306emonth\u306e\u5024\u3092\u4f7f\u3063\u3066\u3001\u7d50\u679c\u3092\u4e26\u3073\u66ff\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\uff081\uff09Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"decode:true \" >Post.includes(:user).where(users: {name: \"\u7acb\u5ddd\u88d5\u7f8e\"}).order(\"posts.month asc\").each { |post| puts \"\u2605 post.id=#{post.id} : post.user.name=#{post.user.name}\" }<\/pre>\n<p>\u5148\u307b\u3069\u8a66\u3057\u305fname=\"\u7acb\u5ddd\u88d5\u7f8e\"\u306eusers\u3060\u3051\u3092\u5bfe\u8c61\u306b\u3057\u305f\u30b3\u30fc\u30c9\u306b<span style=\"color: #339966;\"><strong>\u300c.order(\u201cposts.month asc\u201d)\u300d<\/strong><\/span>\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>order\u306b\u306f\u3001\u4e26\u3073\u66ff\u3048\u306b\u4f7f\u3046\u30ab\u30e9\u30e0\uff08\u4eca\u56de\u306e\u4f8b\u3067\u306f\u3001posts.month\uff09\u3068\u3001\u4e26\u3073\u66ff\u3048\u308b\u9806\u756a\uff08asc\uff1a\u6607\u9806\u3001desc\uff1a\u964d\u9806\uff09\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"striped:false marking:false ranges:false nums:false nums-toggle:false lang:default decode:true \" >  SQL (0.2ms)  SELECT \"posts\".\"id\" AS t0_r0, \"posts\".\"user_id\" AS t0_r1, \"posts\".\"title\" AS t0_r2, \"posts\".\"month\" AS t0_r3, \"posts\".\"created_at\" AS t0_r4, \"posts\".\"updated_at\" AS t0_r5, \"users\".\"id\" AS t1_r0, \"users\".\"name\" AS t1_r1, \"users\".\"created_at\" AS t1_r2, \"users\".\"updated_at\" AS t1_r3 FROM \"posts\" LEFT OUTER JOIN \"users\" ON \"users\".\"id\" = \"posts\".\"user_id\" WHERE \"users\".\"name\" = ? ORDER BY posts.month asc  [[\"name\", \"\u7acb\u5ddd\u88d5\u7f8e\"]]\r\n\u2605 post.id=4 : post.user.name=\u7acb\u5ddd\u88d5\u7f8e\r\n\u2605 post.id=8 : post.user.name=\u7acb\u5ddd\u88d5\u7f8e\r\n\u2605 post.id=3 : post.user.name=\u7acb\u5ddd\u88d5\u7f8e\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| id | user_id | title            | month | created_at      | updated_at       |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n| 4  | 3       | \u5c71\u767b\u308a\u306b\u884c\u304d...  | 8     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 8  | 3       | Ruby on Rails... | 9     | 2018-06-21 1... | 2018-06-21 14... |\r\n| 3  | 3       | \u6628\u65e5\u306e\u51fa\u6765\u4e8b     | 12    | 2018-06-21 1... | 2018-06-21 14... |\r\n+----+---------+------------------+-------+-----------------+------------------+\r\n3 rows in set<\/pre>\n<p>asc\u3092desc\u306b\u5909\u66f4\u3059\u308c\u3070\u3001\u9006\u9806\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306b\u5f71\u97ff\u304c\u51fa\u308b<span style=\"color: #ff0000;\"><strong>N+1\u554f\u984c<\/strong><\/span>\u3092\u3001<span style=\"color: #339966;\"><strong>includes<\/strong><\/span>\u3092\u4f7f\u3063\u3066\u89e3\u6c7a\u3059\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u4eca\u56de\u306fincludes\u3092\u8aac\u660e\u3057\u307e\u3057\u305f\u304c\u3001\u540c\u69d8\u306e\u30e1\u30bd\u30c3\u30c9\uff08<span style=\"color: #339966;\"><strong>joins<\/strong><\/span>\u3001<span style=\"color: #339966;\"><strong>preload<\/strong><\/span>\u3001<span style=\"color: #339966;\"><strong>eager_load<\/strong><\/span>\uff09\u3082\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u3057\u3063\u304b\u308a\u7406\u89e3\u3057\u3066\u3001<span style=\"color: #0000ff\"><strong>\u9069\u6750\u9069\u6240\u3067\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u51fa\u3057\u307e\u3057\u3087\u3046\u3002<\/strong><\/span><\/p>\n<p>\u3053\u308c\u3092\u6a5f\u306b\u305d\u308c\u305e\u308c\u306e\u9055\u3044\u3092\u52c9\u5f37\u3057\u3066\u307f\u3066\u306f\u3044\u304b\u304c\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u3055\u3089\u306b\u3001\u30c7\u30fc\u30bf\u3092\u4e26\u3079\u66ff\u3048\u305f\u72b6\u614b\u3067\u53d6\u5f97\u3059\u308b<span style=\"color: #54a870;\"><strong>order<\/strong><\/span>\/<span style=\"color: #54a870;\"><strong>reorder<\/strong><\/span>\u306e\u4f7f\u3044\u65b9\u3001<span style=\"color: #54a870;\"><strong>order_as_specified gem<\/strong><\/span>\u306e\u4f7f\u3044\u65b9\u3082\u8aac\u660e\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3082\u3057includes\u3084order\u306e\u4f7f\u3044\u65b9\u3092\u5fd8\u308c\u3066\u3057\u307e\u3063\u305f\u3089\u3001\u3053\u306e\u8a18\u4e8b\u3067\u3082\u3046\u4e00\u5ea6\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\u306d\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u307f\u306a\u3055\u3093\u306f\u30012\u3064\u306e\u95a2\u9023\u4ed8\u3051\u3089\u308c\u305f\u30c6\u30fc\u30d6\u30eb\u3092\u6271\u3063\u3066\u3044\u308b\u3068\u304d\u306b\u3001\u3069\u306e\u3088\u3046\u306b\u5024\u3092\u53d6\u308a\u51fa\u3057\u3066\u3044\u307e\u3059\u304b\uff1f \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u6c17\u306b\u305b\u305a\u3001all\u3084join\u3092\u4f7f\u3063\u3066\u3001N+1\u554f\u984c\u3092\u767a\u751f\u3055\u305b\u3066\u3044\u307e\u305b\u3093\u304b\uff1f \u305d\u308c\u3068\u3082\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u6c17\u306b\u3057\u3066\u3001i [&hellip;]<\/p>\n","protected":false},"author":16433,"featured_media":62443,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"swell_btn_cv_data":"","footnotes":""},"categories":[2352],"tags":[493,14],"class_list":["post-26168","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ruby-study","tag-includes","tag-ruby-on-rails"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>\u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\/order\u3092\u691c\u8a0e\u3057\u3088\u3046 | \u4f8d\u30a8\u30f3\u30b8\u30cb\u30a2\u30d6\u30ed\u30b0<\/title>\n<meta name=\"description\" content=\"\u3053\u306e\u8a18\u4e8b\u3067\u306f\u300c \u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\/order\u3092\u691c\u8a0e\u3057\u3088\u3046 \u300d\u306b\u3064\u3044\u3066\u3001\u8ab0\u3067\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u306b\u89e3\u8aac\u3057\u307e\u3059\u3002\u3053\u306e\u8a18\u4e8b\u3092\u8aad\u3081\u3070\u3001\u3042\u306a\u305f\u306e\u60a9\u307f\u304c\u89e3\u6c7a\u3059\u308b\u3060\u3051\u3058\u3083\u306a\u304f\u3001\u65b0\u305f\u306a\u6c17\u4ed8\u304d\u3082\u767a\u898b\u3067\u304d\u308b\u3053\u3068\u3067\u3057\u3087\u3046\u3002\u304a\u60a9\u307f\u306e\u65b9\u306f\u305c\u3072\u3054\u4e00\u8aad\u304f\u3060\u3055\u3044\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sejuku.net\/blog\/26168\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\/order\u3092\u691c\u8a0e\u3057\u3088\u3046 | \u4f8d\u30a8\u30f3\u30b8\u30cb\u30a2\u30d6\u30ed\u30b0\" \/>\n<meta property=\"og:description\" content=\"\u3053\u306e\u8a18\u4e8b\u3067\u306f\u300c \u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\/order\u3092\u691c\u8a0e\u3057\u3088\u3046 \u300d\u306b\u3064\u3044\u3066\u3001\u8ab0\u3067\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u306b\u89e3\u8aac\u3057\u307e\u3059\u3002\u3053\u306e\u8a18\u4e8b\u3092\u8aad\u3081\u3070\u3001\u3042\u306a\u305f\u306e\u60a9\u307f\u304c\u89e3\u6c7a\u3059\u308b\u3060\u3051\u3058\u3083\u306a\u304f\u3001\u65b0\u305f\u306a\u6c17\u4ed8\u304d\u3082\u767a\u898b\u3067\u304d\u308b\u3053\u3068\u3067\u3057\u3087\u3046\u3002\u304a\u60a9\u307f\u306e\u65b9\u306f\u305c\u3072\u3054\u4e00\u8aad\u304f\u3060\u3055\u3044\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sejuku.net\/blog\/26168\" \/>\n<meta property=\"og:site_name\" content=\"\u4f8d\u30a8\u30f3\u30b8\u30cb\u30a2\u30d6\u30ed\u30b0\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/sejuku2013\" \/>\n<meta property=\"article:published_time\" content=\"1970-01-01T00:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-06T02:43:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2017\/06\/rails_order.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"700\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"\u4f8d\u30c6\u30c3\u30af\u7de8\u96c6\u90e8\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@samuraijuku\" \/>\n<meta name=\"twitter:site\" content=\"@samuraijuku\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/26168#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/26168\"},\"author\":{\"name\":\"\u4f8d\u30c6\u30c3\u30af\u7de8\u96c6\u90e8\",\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/#\\\/schema\\\/person\\\/d20c57b59dba15001519a8a671183095\"},\"headline\":\"\u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\\\/order\u3092\u691c\u8a0e\u3057\u3088\u3046\",\"datePublished\":\"1970-01-01T00:00:00+00:00\",\"dateModified\":\"2024-05-06T02:43:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/26168\"},\"wordCount\":409,\"publisher\":{\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/26168#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/06\\\/rails_order.jpg\",\"keywords\":[\"includes\",\"Ruby on Rails\"],\"articleSection\":[\"Ruby\u5b66\u7fd2\"],\"inLanguage\":\"ja\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/26168\",\"url\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/26168\",\"name\":\"\u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\\\/order\u3092\u691c\u8a0e\u3057\u3088\u3046 | \u4f8d\u30a8\u30f3\u30b8\u30cb\u30a2\u30d6\u30ed\u30b0\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/26168#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/26168#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/06\\\/rails_order.jpg\",\"datePublished\":\"1970-01-01T00:00:00+00:00\",\"dateModified\":\"2024-05-06T02:43:39+00:00\",\"description\":\"\u3053\u306e\u8a18\u4e8b\u3067\u306f\u300c \u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\\\/order\u3092\u691c\u8a0e\u3057\u3088\u3046 \u300d\u306b\u3064\u3044\u3066\u3001\u8ab0\u3067\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u306b\u89e3\u8aac\u3057\u307e\u3059\u3002\u3053\u306e\u8a18\u4e8b\u3092\u8aad\u3081\u3070\u3001\u3042\u306a\u305f\u306e\u60a9\u307f\u304c\u89e3\u6c7a\u3059\u308b\u3060\u3051\u3058\u3083\u306a\u304f\u3001\u65b0\u305f\u306a\u6c17\u4ed8\u304d\u3082\u767a\u898b\u3067\u304d\u308b\u3053\u3068\u3067\u3057\u3087\u3046\u3002\u304a\u60a9\u307f\u306e\u65b9\u306f\u305c\u3072\u3054\u4e00\u8aad\u304f\u3060\u3055\u3044\u3002\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/26168#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/26168\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/26168#primaryimage\",\"url\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/06\\\/rails_order.jpg\",\"contentUrl\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/06\\\/rails_order.jpg\",\"width\":700,\"height\":400},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/26168#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\\\/order\u3092\u691c\u8a0e\u3057\u3088\u3046\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/\",\"name\":\"\u4f8d\u30a8\u30f3\u30b8\u30cb\u30a2\u30d6\u30ed\u30b0\",\"description\":\"\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u5b66\u7fd2\u306e\u3059\u3079\u3066\u304c\u30b3\u30b3\u306b\u3002\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ja\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/#organization\",\"name\":\"\u682a\u5f0f\u4f1a\u793eSAMURAI\",\"url\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/logo.png\",\"contentUrl\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/logo.png\",\"width\":600,\"height\":600,\"caption\":\"\u682a\u5f0f\u4f1a\u793eSAMURAI\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/sejuku2013\",\"https:\\\/\\\/x.com\\\/samuraijuku\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCCFOQO5aDK0xXam4cUQXT8g\\\/featured\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/#\\\/schema\\\/person\\\/d20c57b59dba15001519a8a671183095\",\"name\":\"\u4f8d\u30c6\u30c3\u30af\u7de8\u96c6\u90e8\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d91ed20aaa7f873a0f4f35586561303460c1e3864746dddb6ebe0fb093c1952d?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d91ed20aaa7f873a0f4f35586561303460c1e3864746dddb6ebe0fb093c1952d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d91ed20aaa7f873a0f4f35586561303460c1e3864746dddb6ebe0fb093c1952d?s=96&d=mm&r=g\",\"caption\":\"\u4f8d\u30c6\u30c3\u30af\u7de8\u96c6\u90e8\"},\"description\":\"\u4f8d\u30a8\u30f3\u30b8\u30cb\u30a2\u587e\u306f\u300c\u4eba\u751f\u3092\u5909\u3048\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u5b66\u7fd2\u300d\u3092\u30b3\u30f3\u30bb\u30f3\u30d7\u30c8\u306b\u3001\u904e\u53bb\u591a\u304f\u306e\u30d5\u30ea\u30fc\u30e9\u30f3\u30b9\u30a8\u30f3\u30b8\u30cb\u30a2\u3092\u8f29\u51fa\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\u3067\u3059\u3002\u4f8d\u30c6\u30c3\u30af\u7de8\u96c6\u90e8\u3067\u306f\u6280\u8853\u7cfb\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u4e2d\u5fc3\u306b\u6709\u7528\u306a\u60c5\u5831\u3092\u767a\u4fe1\u3057\u3066\u3044\u304d\u307e\u3059\u3002\",\"url\":\"https:\\\/\\\/www.sejuku.net\\\/blog\\\/author\\\/samurai-tech\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\/order\u3092\u691c\u8a0e\u3057\u3088\u3046 | \u4f8d\u30a8\u30f3\u30b8\u30cb\u30a2\u30d6\u30ed\u30b0","description":"\u3053\u306e\u8a18\u4e8b\u3067\u306f\u300c \u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\/order\u3092\u691c\u8a0e\u3057\u3088\u3046 \u300d\u306b\u3064\u3044\u3066\u3001\u8ab0\u3067\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u306b\u89e3\u8aac\u3057\u307e\u3059\u3002\u3053\u306e\u8a18\u4e8b\u3092\u8aad\u3081\u3070\u3001\u3042\u306a\u305f\u306e\u60a9\u307f\u304c\u89e3\u6c7a\u3059\u308b\u3060\u3051\u3058\u3083\u306a\u304f\u3001\u65b0\u305f\u306a\u6c17\u4ed8\u304d\u3082\u767a\u898b\u3067\u304d\u308b\u3053\u3068\u3067\u3057\u3087\u3046\u3002\u304a\u60a9\u307f\u306e\u65b9\u306f\u305c\u3072\u3054\u4e00\u8aad\u304f\u3060\u3055\u3044\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sejuku.net\/blog\/26168","og_locale":"ja_JP","og_type":"article","og_title":"\u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\/order\u3092\u691c\u8a0e\u3057\u3088\u3046 | \u4f8d\u30a8\u30f3\u30b8\u30cb\u30a2\u30d6\u30ed\u30b0","og_description":"\u3053\u306e\u8a18\u4e8b\u3067\u306f\u300c \u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\/order\u3092\u691c\u8a0e\u3057\u3088\u3046 \u300d\u306b\u3064\u3044\u3066\u3001\u8ab0\u3067\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u306b\u89e3\u8aac\u3057\u307e\u3059\u3002\u3053\u306e\u8a18\u4e8b\u3092\u8aad\u3081\u3070\u3001\u3042\u306a\u305f\u306e\u60a9\u307f\u304c\u89e3\u6c7a\u3059\u308b\u3060\u3051\u3058\u3083\u306a\u304f\u3001\u65b0\u305f\u306a\u6c17\u4ed8\u304d\u3082\u767a\u898b\u3067\u304d\u308b\u3053\u3068\u3067\u3057\u3087\u3046\u3002\u304a\u60a9\u307f\u306e\u65b9\u306f\u305c\u3072\u3054\u4e00\u8aad\u304f\u3060\u3055\u3044\u3002","og_url":"https:\/\/www.sejuku.net\/blog\/26168","og_site_name":"\u4f8d\u30a8\u30f3\u30b8\u30cb\u30a2\u30d6\u30ed\u30b0","article_publisher":"https:\/\/www.facebook.com\/sejuku2013","article_published_time":"1970-01-01T00:00:00+00:00","article_modified_time":"2024-05-06T02:43:39+00:00","og_image":[{"width":700,"height":400,"url":"https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2017\/06\/rails_order.jpg","type":"image\/jpeg"}],"author":"\u4f8d\u30c6\u30c3\u30af\u7de8\u96c6\u90e8","twitter_card":"summary_large_image","twitter_creator":"@samuraijuku","twitter_site":"@samuraijuku","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.sejuku.net\/blog\/26168#article","isPartOf":{"@id":"https:\/\/www.sejuku.net\/blog\/26168"},"author":{"name":"\u4f8d\u30c6\u30c3\u30af\u7de8\u96c6\u90e8","@id":"https:\/\/www.sejuku.net\/blog\/#\/schema\/person\/d20c57b59dba15001519a8a671183095"},"headline":"\u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\/order\u3092\u691c\u8a0e\u3057\u3088\u3046","datePublished":"1970-01-01T00:00:00+00:00","dateModified":"2024-05-06T02:43:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.sejuku.net\/blog\/26168"},"wordCount":409,"publisher":{"@id":"https:\/\/www.sejuku.net\/blog\/#organization"},"image":{"@id":"https:\/\/www.sejuku.net\/blog\/26168#primaryimage"},"thumbnailUrl":"https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2017\/06\/rails_order.jpg","keywords":["includes","Ruby on Rails"],"articleSection":["Ruby\u5b66\u7fd2"],"inLanguage":"ja"},{"@type":"WebPage","@id":"https:\/\/www.sejuku.net\/blog\/26168","url":"https:\/\/www.sejuku.net\/blog\/26168","name":"\u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\/order\u3092\u691c\u8a0e\u3057\u3088\u3046 | \u4f8d\u30a8\u30f3\u30b8\u30cb\u30a2\u30d6\u30ed\u30b0","isPartOf":{"@id":"https:\/\/www.sejuku.net\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sejuku.net\/blog\/26168#primaryimage"},"image":{"@id":"https:\/\/www.sejuku.net\/blog\/26168#primaryimage"},"thumbnailUrl":"https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2017\/06\/rails_order.jpg","datePublished":"1970-01-01T00:00:00+00:00","dateModified":"2024-05-06T02:43:39+00:00","description":"\u3053\u306e\u8a18\u4e8b\u3067\u306f\u300c \u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\/order\u3092\u691c\u8a0e\u3057\u3088\u3046 \u300d\u306b\u3064\u3044\u3066\u3001\u8ab0\u3067\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u306b\u89e3\u8aac\u3057\u307e\u3059\u3002\u3053\u306e\u8a18\u4e8b\u3092\u8aad\u3081\u3070\u3001\u3042\u306a\u305f\u306e\u60a9\u307f\u304c\u89e3\u6c7a\u3059\u308b\u3060\u3051\u3058\u3083\u306a\u304f\u3001\u65b0\u305f\u306a\u6c17\u4ed8\u304d\u3082\u767a\u898b\u3067\u304d\u308b\u3053\u3068\u3067\u3057\u3087\u3046\u3002\u304a\u60a9\u307f\u306e\u65b9\u306f\u305c\u3072\u3054\u4e00\u8aad\u304f\u3060\u3055\u3044\u3002","breadcrumb":{"@id":"https:\/\/www.sejuku.net\/blog\/26168#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sejuku.net\/blog\/26168"]}]},{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.sejuku.net\/blog\/26168#primaryimage","url":"https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2017\/06\/rails_order.jpg","contentUrl":"https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2017\/06\/rails_order.jpg","width":700,"height":400},{"@type":"BreadcrumbList","@id":"https:\/\/www.sejuku.net\/blog\/26168#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sejuku.net\/blog\/"},{"@type":"ListItem","position":2,"name":"\u3010Rails\u5165\u9580\u3011\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u3044\u306a\u3089includes\/order\u3092\u691c\u8a0e\u3057\u3088\u3046"}]},{"@type":"WebSite","@id":"https:\/\/www.sejuku.net\/blog\/#website","url":"https:\/\/www.sejuku.net\/blog\/","name":"\u4f8d\u30a8\u30f3\u30b8\u30cb\u30a2\u30d6\u30ed\u30b0","description":"\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u5b66\u7fd2\u306e\u3059\u3079\u3066\u304c\u30b3\u30b3\u306b\u3002","publisher":{"@id":"https:\/\/www.sejuku.net\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sejuku.net\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ja"},{"@type":"Organization","@id":"https:\/\/www.sejuku.net\/blog\/#organization","name":"\u682a\u5f0f\u4f1a\u793eSAMURAI","url":"https:\/\/www.sejuku.net\/blog\/","logo":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.sejuku.net\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2023\/07\/logo.png","contentUrl":"https:\/\/www.sejuku.net\/blog\/wp-content\/uploads\/2023\/07\/logo.png","width":600,"height":600,"caption":"\u682a\u5f0f\u4f1a\u793eSAMURAI"},"image":{"@id":"https:\/\/www.sejuku.net\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/sejuku2013","https:\/\/x.com\/samuraijuku","https:\/\/www.youtube.com\/channel\/UCCFOQO5aDK0xXam4cUQXT8g\/featured"]},{"@type":"Person","@id":"https:\/\/www.sejuku.net\/blog\/#\/schema\/person\/d20c57b59dba15001519a8a671183095","name":"\u4f8d\u30c6\u30c3\u30af\u7de8\u96c6\u90e8","image":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/secure.gravatar.com\/avatar\/d91ed20aaa7f873a0f4f35586561303460c1e3864746dddb6ebe0fb093c1952d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d91ed20aaa7f873a0f4f35586561303460c1e3864746dddb6ebe0fb093c1952d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d91ed20aaa7f873a0f4f35586561303460c1e3864746dddb6ebe0fb093c1952d?s=96&d=mm&r=g","caption":"\u4f8d\u30c6\u30c3\u30af\u7de8\u96c6\u90e8"},"description":"\u4f8d\u30a8\u30f3\u30b8\u30cb\u30a2\u587e\u306f\u300c\u4eba\u751f\u3092\u5909\u3048\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u5b66\u7fd2\u300d\u3092\u30b3\u30f3\u30bb\u30f3\u30d7\u30c8\u306b\u3001\u904e\u53bb\u591a\u304f\u306e\u30d5\u30ea\u30fc\u30e9\u30f3\u30b9\u30a8\u30f3\u30b8\u30cb\u30a2\u3092\u8f29\u51fa\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\u3067\u3059\u3002\u4f8d\u30c6\u30c3\u30af\u7de8\u96c6\u90e8\u3067\u306f\u6280\u8853\u7cfb\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u4e2d\u5fc3\u306b\u6709\u7528\u306a\u60c5\u5831\u3092\u767a\u4fe1\u3057\u3066\u3044\u304d\u307e\u3059\u3002","url":"https:\/\/www.sejuku.net\/blog\/author\/samurai-tech"}]}},"_links":{"self":[{"href":"https:\/\/www.sejuku.net\/blog\/wp-json\/wp\/v2\/posts\/26168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sejuku.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sejuku.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sejuku.net\/blog\/wp-json\/wp\/v2\/users\/16433"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sejuku.net\/blog\/wp-json\/wp\/v2\/comments?post=26168"}],"version-history":[{"count":0,"href":"https:\/\/www.sejuku.net\/blog\/wp-json\/wp\/v2\/posts\/26168\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sejuku.net\/blog\/wp-json\/wp\/v2\/media\/62443"}],"wp:attachment":[{"href":"https:\/\/www.sejuku.net\/blog\/wp-json\/wp\/v2\/media?parent=26168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sejuku.net\/blog\/wp-json\/wp\/v2\/categories?post=26168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sejuku.net\/blog\/wp-json\/wp\/v2\/tags?post=26168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}