{"id":1103,"date":"2019-11-29T09:20:22","date_gmt":"2019-11-29T00:20:22","guid":{"rendered":"https:\/\/naoya-ono.com\/blog\/?p=1103"},"modified":"2019-11-29T12:36:29","modified_gmt":"2019-11-29T03:36:29","slug":"fuelphp-join","status":"publish","type":"post","link":"https:\/\/naoya-ono.com\/blog\/fuelphp-join\/","title":{"rendered":"\u3010FuelPHP\u306e\u4f7f\u3044\u65b9\u3011\u30c6\u30fc\u30d6\u30eb\u3092JOIN\u3057\u3066\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<div class=\"memo \">\n<div class=\"memo_ttl dfont\"> \u59cb\u3081\u306b<\/div>\n<p>\u3053\u306e\u30da\u30fc\u30b8\u306f\u3001PHP\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u300c<strong>FuelPHP<\/strong>\u300d\u306e\u5b66\u7fd2\u4e2d\u306e\u50d5\u304c\u30e1\u30e2\u3068\u3057\u3066\u6b8b\u3057\u3066\u3044\u308b\u3082\u306e\u3067\u3059\u3002\u5185\u5bb9\u306b\u9593\u9055\u3044\u304c\u3042\u308c\u3070\u3054\u9023\u7d61\u3044\u305f\u3060\u3051\u308b\u3068\u5e78\u3044\u3067\u3059\u3002<\/p>\n<\/div>\n<p>FuePHP\u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30c6\u30fc\u30d6\u30eb\u3092Join\u3057\u305f\u3044\u5834\u5408\u306f\u3001<strong>Query_Builder_Select\u30af\u30e9\u30b9<\/strong><span>\u306e<\/span><strong>join()\u30e1\u30bd\u30c3\u30c9<\/strong>\u3068\u3001<strong>on()\u30e1\u30bd\u30c3\u30c9<\/strong>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u4f7f\u3044\u65b9\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">\u76ee\u6b21<\/p><ul class=\"toc_list\"><li><a href=\"#join\">join()\u30e1\u30bd\u30c3\u30c9\u306e\u66f8\u304d\u65b9<\/a><\/li><li><a href=\"#on\">on()\u30e1\u30bd\u30c3\u30c9\u306e\u66f8\u304d\u65b9<\/a><\/li><li><a href=\"#i\">\u5b9f\u969b\u306e\u30b3\u30fc\u30c9\u30b5\u30f3\u30d7\u30eb<\/a><\/li><\/ul><\/div>\n<h2 class=\"hh hh5 pastel-bc\" id=\"i-0\"><span id=\"join\">join()\u30e1\u30bd\u30c3\u30c9\u306e\u66f8\u304d\u65b9<\/span><\/h2>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/blog\/wp-content\/uploads\/2019\/11\/join-method.jpg\" alt=\"\" width=\"700\" height=\"150\" class=\"wp-image-1127 size-full aligncenter img_border\" srcset=\"https:\/\/naoya-ono.com\/blog\/wp-content\/uploads\/2019\/11\/join-method.jpg 700w, https:\/\/naoya-ono.com\/blog\/wp-content\/uploads\/2019\/11\/join-method-300x64.jpg 300w\" sizes=\"(max-width: 700px) 100vw, 700px\"><\/p>\n<p>join()\u30e1\u30bd\u30c3\u30c9\u306e\u7b2c\u4e00\u5f15\u6570\u306b\u306f\u300c\u7d50\u5408\u3057\u305f\u3044\u30c6\u30fc\u30d6\u30eb\u540d\u300d\u3001\u7b2c\u4e8c\u5f15\u6570\u306b\u306f\u300c\u7d50\u5408\u65b9\u6cd5\u300d\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p>\u7d50\u5408\u65b9\u6cd5\u3068\u306f\u300cLEFT\u300d\u3068\u304b\u300cRIGHT\u300d\u3068\u304b\u3067\u3059\u3002<\/p>\n<h2 class=\"hh hh5 pastel-bc\" id=\"i-1\"><span id=\"on\">on()\u30e1\u30bd\u30c3\u30c9\u306e\u66f8\u304d\u65b9<\/span><\/h2>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/blog\/wp-content\/uploads\/2019\/11\/on-method.jpg\" alt=\"\" width=\"700\" height=\"150\" class=\"wp-image-1130 size-full aligncenter img_border\" srcset=\"https:\/\/naoya-ono.com\/blog\/wp-content\/uploads\/2019\/11\/on-method.jpg 700w, https:\/\/naoya-ono.com\/blog\/wp-content\/uploads\/2019\/11\/on-method-300x64.jpg 300w\" sizes=\"(max-width: 700px) 100vw, 700px\"><\/p>\n<p>on()\u30e1\u30bd\u30c3\u30c9\u306b\u306f\u7d50\u5408\u306e\u305f\u3081\u306b\u6bd4\u8f03\u3059\u308b\u30ab\u30e9\u30e0\u540d\u3068\u6f14\u7b97\u5b50\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<h2 class=\"hh hh5 pastel-bc\" id=\"i-2\"><span id=\"i\">\u5b9f\u969b\u306e\u30b3\u30fc\u30c9\u30b5\u30f3\u30d7\u30eb<\/span><\/h2>\n<p>\u3053\u308c\u306f\u5b9f\u969b\u306b\u50d5\u304cFuelPHP\u3067\u4f5c\u3063\u305f\u672c\u306e\u30ec\u30d3\u30e5\u30fc\u30b5\u30a4\u30c8\u304b\u3089\u30b3\u30fc\u30c9\u3092\u629c\u7c8b\u3057\u305f\u3082\u306e\u3067\u3059\u3002<\/p>\n<p><span class=\"labeltext accent-bc\">Model\u306e\u5185\u5bb9<\/span><\/p>\n<div>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>public function get_reviews($book_id){\n\n  $query = DB::select()-&gt;from('reviews');\n  $query-&gt;where('book_id', '=', $book_id );\n  $query-&gt;join('users','LEFT' );\n  $query-&gt;on('reviews.user_id', '=', 'users.id' );\n\n  $result = $query-&gt;execute()-&gt;as_array();\n  return $result;\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<p>\u4e0a\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306freviews\u30c6\u30fc\u30d6\u30eb\u3068\u3001users\u30c6\u30fc\u30d6\u30eb\u3092\u30e6\u30fc\u30b6\u30fcID\u3067\u7d50\u5408\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u7406\u7531\u306fusesr\u30c6\u30fc\u30d6\u30eb\u306b\u5165\u3063\u3066\u3044\u308b\u30e6\u30fc\u30b6\u30fc\u540d\u304c\u6b32\u3057\u304b\u3063\u305f\u305f\u3081\u3067\u3059\u3002<\/p>\n<p>reviews\u30c6\u30fc\u30d6\u30eb\u306b\u306f\u672c\u306e\u30ec\u30d3\u30e5\u30fc\u60c5\u5831\u304c\u5165\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u30ec\u30d3\u30e5\u30fc\u8005\u306e\u60c5\u5831\u306f\u30e6\u30fc\u30b6\u30fcID\u3057\u304b\u306a\u3044\u305f\u3081\u3001\u753b\u9762\u306b\u30ec\u30d3\u30e5\u30fc\u8005\u306e\u540d\u524d\u3092\u8868\u793a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u4e0a\u306e\u3088\u3046\u306busesr\u30c6\u30fc\u30d6\u30eb\u3068\u7d50\u5408\u3057\u3066\u30e6\u30fc\u30b6\u30fc\u540d\u3092\u5f15\u3063\u5f35\u3063\u3066\u304d\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u4e0a\u306e\u30b3\u30fc\u30c9\u306b\u3088\u3063\u3066\u767a\u884c\u3055\u308c\u308bSQL\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<span><\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>SELECT * FROM reviews LEFT JOIN users ON reviews.user_id = users.id where book_id = \u672c\u306eID;<\/code><\/pre>\n<\/div>\n<p>\u306a\u3093\u3068\u306a\u304f\u4f7f\u3044\u65b9\u304c\u308f\u304b\u308a\u307e\u3057\u305f\u304b\uff1f<\/p>\n<p>FuelPHP\u3067\u3001\u30c6\u30fc\u30d6\u30eb\u3092Join\u3057\u305f\u3044\u5834\u5408\u306fjoin()\u30e1\u30bd\u30c3\u30c9\u3068\u3001on()\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3068\u3044\u3046\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n<p>\u3061\u306a\u307f\u306b\u516c\u5f0f\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u306f\u3053\u3061\u3089\u3067\u3059\u3002<\/p>\n<p>  <a class=\"reference table\" href=\"http:\/\/fuelphp.jp\/docs\/1.7\/classes\/database\/qb_select.html\" rel=\"noopener noreferrer\"><br \/>\n    <span class=\"tbcell refttl\">\u53c2\u8003<\/span><br \/>\n    <span class=\"tbcell refcite\">Query Builder Select \u30af\u30e9\u30b9<span>FuelPHP\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/span><\/span><br \/>\n  <\/a><\/p>\n<p>\u5c1a\u3001FuelPHP\u306b\u3064\u3044\u3066\u3082\u3063\u3068\u77e5\u308a\u305f\u3044\u3068\u3044\u3046\u4eba\u306f\u4ee5\u4e0b\u306e\u672c\u304c\u304a\u3059\u3059\u3081\u3067\u3059\u3002<\/p>\n<div id=\"rinkerid1181\" class=\"yyi-rinker-contents  yyi-rinker-postid-1181 yyi-rinker-img-m yyi-rinker-catid-12 yyi-rinker-catid-3 \">\n<div class=\"yyi-rinker-box\">\n<div class=\"yyi-rinker-image\">\n\t\t\t\t\t\t\t<a href=\"https:\/\/www.amazon.co.jp\/dp\/4800710642?tag=naoya-ono-22&amp;linkCode=ogi&amp;th=1&amp;psc=1\" rel=\"nofollow\" class=\"yyi-rinker-tracking\" data-click-tracking=\"amazon_img 1181 \u6539\u8a02 FuelPHP\u5165\u9580\" data-vars-click-id=\"amazon_img 1181 \u6539\u8a02 FuelPHP\u5165\u9580\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/m.media-amazon.com\/images\/I\/51eQlQPe6TL._SL160_.jpg\" width=\"125\" height=\"160\" class=\"yyi-rinker-main-img\" style=\"border: none;\"><\/a>\t\t\t\t\t<\/div>\n<div class=\"yyi-rinker-info\">\n<div class=\"yyi-rinker-title\">\n\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/www.amazon.co.jp\/dp\/4800710642?tag=naoya-ono-22&amp;linkCode=ogi&amp;th=1&amp;psc=1\" rel=\"nofollow\" class=\"yyi-rinker-tracking\" data-click-tracking=\"amazon_title 1181 \u6539\u8a02 FuelPHP\u5165\u9580\" data-vars-amp-click-id=\"amazon_title 1181 \u6539\u8a02 FuelPHP\u5165\u9580\">\u6539\u8a02 FuelPHP\u5165\u9580<\/a>\t\t\t\t\t\t\t<\/div>\n<div class=\"yyi-rinker-detail\">\n<div class=\"credit-box\">created by&nbsp;<a href=\"https:\/\/oyakosodate.com\/rinker\/\" rel=\"nofollow noopener\" target=\"_blank\">Rinker<\/a><\/div>\n<div class=\"price-box\">\n\t\t\t\t\t\t\t<\/div>\n<\/p><\/div>\n<ul class=\"yyi-rinker-links\">\n<li class=\"amazonkindlelink\">\n\t\t\t\t\t\t<a href=\"https:\/\/www.amazon.co.jp\/gp\/product\/B00OZGM9VI\/ref=as_li_qf_asin_il_tl?ie=UTF8&amp;tag=naoya-ono-22&amp;creative=1211&amp;linkCode=as2&amp;creativeASIN=B00OZGM9VI&amp;linkId=e7f48e4daa6fff821fa6a5936e410ccd\" rel=\"nofollow\" class=\"yyi-rinker-link yyi-rinker-tracking\" data-click-tracking=\"amazon_kindle 1181 \u6539\u8a02 FuelPHP\u5165\u9580\" data-vars-amp-click-id=\"amazon_kindle 1181 \u6539\u8a02 FuelPHP\u5165\u9580\">Kindle<\/a>\t\t\t\t\t<\/li>\n<li class=\"amazonlink\">\n\t\t\t\t\t\t<a href=\"https:\/\/www.amazon.co.jp\/dp\/4800710642?tag=naoya-ono-22&amp;linkCode=ogi&amp;th=1&amp;psc=1\" rel=\"nofollow\" class=\"yyi-rinker-link yyi-rinker-tracking\" data-click-tracking=\"amazon 1181 \u6539\u8a02 FuelPHP\u5165\u9580\" data-vars-amp-click-id=\"amazon 1181 \u6539\u8a02 FuelPHP\u5165\u9580\">Amazon<\/a>\t\t\t\t\t<\/li>\n<li class=\"rakutenlink\">\n\t\t\t\t\t\t<a href=\"https:\/\/hb.afl.rakuten.co.jp\/hgc\/16781883.64066d33.16781884.4f333982\/Rinker_o_20191129121916?pc=https%3A%2F%2Fsearch.rakuten.co.jp%2Fsearch%2Fmall%2FFuelPHP%25E5%2585%25A5%25E9%2596%2580%25E6%2594%25B9%25E8%25A8%2582%2F%3Ff%3D1%26grp%3Dproduct&amp;m=https%3A%2F%2Fsearch.rakuten.co.jp%2Fsearch%2Fmall%2FFuelPHP%25E5%2585%25A5%25E9%2596%2580%25E6%2594%25B9%25E8%25A8%2582%2F%3Ff%3D1%26grp%3Dproduct\" rel=\"nofollow\" class=\"yyi-rinker-link yyi-rinker-tracking\" data-click-tracking=\"rakuten 1181 \u6539\u8a02 FuelPHP\u5165\u9580\" data-vars-amp-click-id=\"rakuten 1181 \u6539\u8a02 FuelPHP\u5165\u9580\">\u697d\u5929\u5e02\u5834<\/a>\t\t\t\t\t<\/li>\n<li class=\"yahoolink\">\n\t\t\t\t\t\t<a href=\"https:\/\/shopping.yahoo.co.jp\/search?p=FuelPHP%E5%85%A5%E9%96%80%E6%94%B9%E8%A8%82\" rel=\"nofollow\" class=\"yyi-rinker-link yyi-rinker-tracking\" data-click-tracking=\"yahoo 1181 \u6539\u8a02 FuelPHP\u5165\u9580\" data-vars-amp-click-id=\"yahoo 1181 \u6539\u8a02 FuelPHP\u5165\u9580\">Yahoo\u30b7\u30e7\u30c3\u30d4\u30f3\u30b0<\/a>\t\t\t\t\t<\/li>\n<li class=\"freelink2\">\n\t\t\t\t\t\t<a href=\"https:\/\/ck.jp.ap.valuecommerce.com\/servlet\/referral?sid=3490090&amp;pid=886213926&amp;vc_url=https%3A%2F%2Fwww.kinokuniya.co.jp%2Ff%2Fdsg-01-9784800710642&amp;vcpub=0.385398&amp;vcid=KQI63vFBqTZKzp_mKHNhDL88-TLcfurZXUncSyO4L1lMfzhKJMp4iElAZ6gtclOxN4PgppL2OGXu-LJ2vQT8VHBonUmDiWFfSoSwZDvsiu-P1enKuOTSkT74zES6mNh6SaSRcPdhAR2wbRh-mkl3NlD65o7XCA0y&amp;isec=1574997808\" rel=\"nofollow\" class=\"yyi-rinker-link yyi-rinker-tracking\" data-click-tracking=\"free_2 1181 \u6539\u8a02 FuelPHP\u5165\u9580\" data-vars-amp-click-id=\"free_2 1181 \u6539\u8a02 FuelPHP\u5165\u9580\">\u7d00\u4f0a\u570b\u5c4b\u66f8\u5e97<\/a>\t\t\t\t\t<\/li>\n<\/ul><\/div>\n<\/p><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>FuePHP\u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30c6\u30fc\u30d6\u30eb\u3092Join\u3057\u305f\u3044\u5834\u5408\u306f\u3001Query_Builder_Select\u30af\u30e9\u30b9\u306ejoin()\u30e1\u30bd\u30c3\u30c9\u3068\u3001on()\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3044\u307e\u3059\u3002 \u305d\u306e\u4f7f\u3044\u65b9\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002 \u76ee\u6b21join()\u30e1\u30bd &#8230; <\/p>\n","protected":false},"author":1,"featured_media":1146,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,3],"tags":[],"_links":{"self":[{"href":"https:\/\/naoya-ono.com\/blog\/wp-json\/wp\/v2\/posts\/1103"}],"collection":[{"href":"https:\/\/naoya-ono.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/naoya-ono.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/naoya-ono.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/naoya-ono.com\/blog\/wp-json\/wp\/v2\/comments?post=1103"}],"version-history":[{"count":30,"href":"https:\/\/naoya-ono.com\/blog\/wp-json\/wp\/v2\/posts\/1103\/revisions"}],"predecessor-version":[{"id":1187,"href":"https:\/\/naoya-ono.com\/blog\/wp-json\/wp\/v2\/posts\/1103\/revisions\/1187"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/naoya-ono.com\/blog\/wp-json\/wp\/v2\/media\/1146"}],"wp:attachment":[{"href":"https:\/\/naoya-ono.com\/blog\/wp-json\/wp\/v2\/media?parent=1103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/naoya-ono.com\/blog\/wp-json\/wp\/v2\/categories?post=1103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/naoya-ono.com\/blog\/wp-json\/wp\/v2\/tags?post=1103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}