{"id":262,"date":"2023-05-10T14:30:00","date_gmt":"2023-05-10T05:30:00","guid":{"rendered":"https:\/\/blog.fundely.co.jp\/tech\/?p=262"},"modified":"2023-07-05T17:26:28","modified_gmt":"2023-07-05T08:26:28","slug":"activerecord%e3%81%ab%e9%96%a2%e3%81%99%e3%82%8b%e6%a7%98%e3%80%85%e3%81%aa%e7%9f%a5%e8%a6%8b","status":"publish","type":"post","link":"https:\/\/blog.fundely.co.jp\/tech\/2023\/05\/10\/activerecord%e3%81%ab%e9%96%a2%e3%81%99%e3%82%8b%e6%a7%98%e3%80%85%e3%81%aa%e7%9f%a5%e8%a6%8b\/","title":{"rendered":"ActiveRecord\u306b\u95a2\u3059\u308b\u69d8\u3005\u306a\u77e5\u898b"},"content":{"rendered":"\n<p>\u3053\u3093\u306b\u3061\u306f\u3002<br>\u30c7\u30b6\u30a4\u30f3\u30fb\u30b7\u30b9\u30c6\u30e0\u5ba4\u306e\u5742\u4e95\u3067\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u4eca\u56de\u306f\u3001\u7686\u3055\u3093Rails\u3067\u304a\u99b4\u67d3\u307f\u306eActiveRecord\u306b\u3064\u3044\u3066\u8a71\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u524d\u534a\u306f\u57fa\u672c\u306e\u8a71\u3067\u3001\u5f8c\u534a\u306f\u5b9f\u52d9\u3067\u4f7f\u3063\u305f\u4e8b\u3092\u8a71\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>ActiveRecord\u306e\u7406\u89e3\u306b\u81ea\u4fe1\u304c\u7121\u3044\u65b9\u306b\u8aad\u3093\u3067\u9802\u3051\u308c\u3070\u5e78\u3044\u3067\u3059\uff01<\/p>\n\n\n\n<div style=\"height:36px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u305d\u3082\u305d\u3082ActiveRecord\u3068\u306f\uff08\u57fa\u672c\uff09<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/blog.fundely.co.jp\/tech\/wp-content\/uploads\/sites\/2\/2023\/05\/active_record.png\" alt=\"\" class=\"wp-image-328\" srcset=\"https:\/\/blog.fundely.co.jp\/tech\/wp-content\/uploads\/sites\/2\/2023\/05\/active_record.png 1024w, https:\/\/blog.fundely.co.jp\/tech\/wp-content\/uploads\/sites\/2\/2023\/05\/active_record-300x169.png 300w, https:\/\/blog.fundely.co.jp\/tech\/wp-content\/uploads\/sites\/2\/2023\/05\/active_record-768x432.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ruby on Rails\u3067\u63a1\u7528\u3055\u308c\u3066\u3044\u308bOR Mapper\u306e\u3053\u3068\u3067\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-pullquote has-text-align-left\"><blockquote><p>\u203bOR Mapper\u3068\u306f<br>\u300c\u76f4\u63a5SQL\u6587\u3092\u66f8\u304f\u4ee3\u308f\u308a\u306b\u975e\u5e38\u306b\u77ed\u3044\u30b3\u30fc\u30c9\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u8aad\u307f\u66f8\u304d\u3092\u884c\u3048\u308b\u6a5f\u80fd\u300d<br>\u3092ORM (\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30ea\u30ec\u30fc\u30b7\u30e7\u30ca\u30eb\u30de\u30c3\u30d4\u30f3\u30b0)\u3068\u3044\u3044\u3001<br>OR Mapper\u3068\u306f\u3001\u305d\u306e\u305f\u3081\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u306a\u308a\u307e\u3059\u3002<\/p><\/blockquote><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30e2\u30c7\u30eb\u3068\u30c6\u30fc\u30d6\u30eb\u3092\u3064\u306a\u304e\u5408\u308f\u305b\u308b\u3053\u3068\u3067Rails\u304b\u3089\u30c6\u30fc\u30d6\u30eb\u306e\u30ec\u30b3\u30fc\u30c9\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u5f79\u5272\u304c\u3042\u308a\u307e\u3059\u3002<\/li>\n\n\n\n<li>Rails\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u304a\u308a\u3001\u5b9f\u969b\u306b\u5229\u7528\u3059\u308b\u969b\u306b\u306f&nbsp;<code>ActiveRecord::Base<\/code>&nbsp;\u3068\u3044\u3046\u30af\u30e9\u30b9\u3092\u7d99\u627f\u3057\u3066\u4f7f\u7528\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u2193<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ActiveRecord::Base\u3068\u306f\uff08\u57fa\u672c\uff09<\/h2>\n\n\n\n<p>Ruby on Rails\u3067\u4f7f\u7528\u3055\u308c\u308bORM(\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30ea\u30ec\u30fc\u30b7\u30e7\u30ca\u30eb\u30de\u30c3\u30d4\u30f3\u30b0)\u306e\u57fa\u5e95\u30af\u30e9\u30b9\uff08<strong>\u7d99\u627f\u5143\u306e\u30af\u30e9\u30b9<\/strong>\uff09\u306e\u3053\u3068\u3067\u3059\u3002<\/p>\n\n\n\n<p>app\/models\/application_record.rb<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>class ApplicationRecord &lt; ActiveRecord::Base<\/code><\/pre><\/div>\n\n\n\n<p>\u2193<\/p>\n\n\n\n<p>\u30e2\u30c7\u30eb\u30af\u30e9\u30b9\u306fActiveRecord::Base\u3092\u7d99\u627f\u3059\u308b\u3053\u3068\u3067\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u306e\u30a2\u30af\u30bb\u30b9\u3084\u64cd\u4f5c\u3092\u7c21\u5358\u306b\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>ex)app\/models\/user.rb<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>class User &lt; ApplicationRecord<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u308c\u306b\u3088\u308a\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3067\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u30e6\u30fc\u30b6\u30fc\u30ec\u30b3\u30fc\u30c9\u3092\u53d6\u5f97\u3057\u305f\u308a\u3001<\/p>\n\n\n\n<p>\u65b0\u3057\u3044\u30e6\u30fc\u30b6\u30fc\u30ec\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>user = User.find(1)\nuser = User.create(name: &quot;John Doe&quot;, email: &quot;johndoe@example.com&quot;)<\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001ActiveRecord::Base\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30e1\u30bd\u30c3\u30c9\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>find<\/li>\n\n\n\n<li>create<\/li>\n\n\n\n<li>update<\/li>\n\n\n\n<li>destroy<\/li>\n\n\n\n<li>save<\/li>\n\n\n\n<li>all<\/li>\n\n\n\n<li>where<\/li>\n\n\n\n<li>order<\/li>\n\n\n\n<li>limit<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>\u305d\u306e\u307b\u304b\u306b\u3082\u3001<\/p>\n\n\n\n<p><code>ActiveRecord::Base<\/code>\u3092\u7d99\u627f\u3057\u305f\u30af\u30e9\u30b9\u306f\u3001<\/p>\n\n\n\n<p>\u2460\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30c6\u30fc\u30d6\u30eb\u3068\u306e\u95a2\u9023\u4ed8\u3051\uff08\u30af\u30e9\u30b9\u540d\u306f\u30c6\u30fc\u30d6\u30eb\u540d\u3068\u5bfe\u5fdc\u3057\u3066\u304a\u308a\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u30c6\u30fc\u30d6\u30eb\u540d\u306f\u30af\u30e9\u30b9\u540d\u306e\u8907\u6570\u5f62\uff09<\/p>\n\n\n\n<p>\u3092\u884c\u3063\u3066\u304f\u308c\u305f\u308a\u3001<\/p>\n\n\n\n<p>\u2461\u30c7\u30fc\u30bf\u306e\u59a5\u5f53\u6027\u3092\u691c\u8a3c\u3059\u308b\u305f\u3081\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u6a5f\u80fd\u3092\u63d0\u4f9b\u3057\u3066\u304f\u308c\u305f\u308a\u3001<\/p>\n\n\n\n<p>\u2462\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u306e\u30c7\u30fc\u30bf\u691c\u7d22\u3092\u884c\u3063\u305f\u308a\u3001<\/p>\n\n\n\n<p>\u2463\u30c7\u30fc\u30bf\u306e\u4f5c\u6210\u3001\u66f4\u65b0\u3001\u524a\u9664\u306a\u3069\u306e\u30a4\u30d9\u30f3\u30c8\u767a\u751f\u6642\u306b\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u305f\u3081\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u6a5f\u80fd\u3092\u63d0\u4f9b\u3057\u3066\u304f\u308c\u308b\u4fbf\u5229\u306a\u3082\u306e\u3067\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9f\u52d9\u3067\u6271\u3063\u305fActiveRecord<\/h2>\n\n\n\n<p>\u5b9f\u52d9\u3067\u306frails console\u306b\u3066\u3001\u2462\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u306e\u30c7\u30fc\u30bf\u691c\u7d22\u3000\u3092\u884c\u3046\u3053\u3068\u304c\u591a\u3044\u3067\u3059\u3002<\/p>\n\n\n\n<p>console\u306e\u4e8b\u4f8b(\u308f\u304b\u308a\u3084\u3059\u304f\u3059\u308b\u305f\u3081\u30e2\u30c7\u30eb\u306a\u3069\u306f\u6539\u5909)<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>ex) User\u306eid\u304c999999\u304b\u3064\u3001\u73fe\u5728\u304b\u30892\u30f6\u6708\u524d\u307e\u3067\u306e\u6295\u7a3f\u3092\u691c\u7d22<\/li>\n<\/ul>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>Post.where(user_id: 999999, published_at: Time.now.ago(2.month)..Time.now)<\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>ex) 2019\u5e745\u67081\u65e5\u3088\u308a\u904e\u53bb\u306e\u6295\u7a3f\u3092\u691c\u7d22<\/li>\n<\/ul>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>Post.where.not(published_at: Time.local(2019,5,1)..Float::INFINITY)<\/code><\/pre><\/div>\n\n\n\n<p>\u203b\u6b63\u306e\u7121\u9650\u5927&nbsp;<code>Float::INFINITY<\/code>&nbsp;\u3092\u6307\u5b9a\u3057\u3066\u3001\u300c\u3042\u308b\u65e5\u4ed8\u3092\u8d8a\u3048\u305f\u65e5\u4ed8\u3092\u6301\u3064\u30ec\u30b3\u30fc\u30c9\u300d\u3092\u8868\u3059\u3053\u3068\u304c\u51fa\u6765\u308b\u306e\u3067\u3059\u304c\u3001<\/p>\n\n\n\n<p>\u8ca0\u306e\u7121\u9650\u5927\u306e\u3001<code>-::Float::INFINITY..Time.local(2019,5,1)<\/code>\u3068\u3057\u3066\u30012019\u5e745\u67081\u65e5\u3088\u308a\u4ee5\u524d\u306e\u65e5\u4ed8\u3092\u691c\u7d22\u3059\u308b\u3068\u3001<\/p>\n\n\n\n<p>ArgumentError: bad value for range<\/p>\n\n\n\n<p>\u3068\u3044\u3046\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u305f\u3081\u3001<code>not<\/code>&nbsp;\u3092\u4f7f\u3044\u3001\u3042\u304f\u307e\u3067\u6b63\u306e\u7121\u9650\u5927\u3092\u7bc4\u56f2\u306b\u6307\u5b9a\u3057\u3066\u3042\u3052\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>ex) \u5927\u91cf\u306e\u30c7\u30fc\u30bf\u3092\u6271\u3046find_each\u306b\u3064\u3044\u3066\u306e\u4e8b\u4f8b<\/li>\n<\/ul>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>Data.where(device_type_id: washing_t).find_each do |washing_t_data|\n  p washing_t_data.appliance_id\nend<\/code><\/pre><\/div>\n\n\n\n<p>\u5927\u91cf\u306e\u30c7\u30fc\u30bf\u3092\u6271\u3046\u5834\u5408\u306f\u3001find_each\u3092\u4f7f\u3063\u3066\u5927\u91cf\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u30eb\u30fc\u30d7\u51e6\u7406\u3059\u308b\u969b\u306b\u30e1\u30e2\u30ea\u306e\u6d88\u8cbb\u91cf\u3092\u6291\u3048\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n\n\n\n<p>1\u4e07\u4ef6\u3092\u8d85\u3048\u308b\u5927\u91cf\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u4e00\u5ea6\u306b\u53d6\u5f97\u3057\u3066\u30eb\u30fc\u30d7\u51e6\u7406\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001<strong>\u30e1\u30e2\u30ea\u304c\u5727\u8feb\u3055\u308c\u3066\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u52d5\u4f5c\u304c\u9045\u304f\u306a\u3063\u305f\u308a\u3001\u30d5\u30ea\u30fc\u30ba\u3057\u3066\u3057\u307e\u3046\u6050\u308c<\/strong>\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u306e\u305f\u3081\u3001\u5927\u91cf\u306e\u30c7\u30fc\u30bf\u3092\u6271\u3046\u5834\u5408\u306b\u306ffind_each\u306f\u3068\u3066\u3082\u91cd\u5b9d\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u904e\u53bb\u306b\u81ea\u5206\u304c\u30cf\u30de\u3063\u305f\u4e8b\u4f8b\u2460<\/h2>\n\n\n\n<p>\u4e0a\u306b\u66f8\u3044\u305f\u69d8\u306b\u69d8\u3005\u306a\u6761\u4ef6\u3067\u691c\u7d22\u3092\u304b\u3051\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u304c\u3001\u904e\u53bb\u306b\u81ea\u5206\u304c\u4f55\u6545\u4e0a\u624b\u304f\u3044\u304b\u306a\u3044\u306e\u304b\u3059\u3050\u306b\u5206\u304b\u3089\u306a\u304b\u3063\u305f\u4e8b\u4f8b\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u2193\u30e6\u30fc\u30b6\u30fc\u3092\u6301\u305f\u306a\u3044\u6a5f\u5668\u3067\u3001\u30dd\u30a4\u30f3\u30c8\u30921\u30dd\u30a4\u30f3\u30c8\u4ee5\u4e0a\u6301\u3063\u3066\u3044\u308b\u6a5f\u5668\u3092\u691c\u7d22<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>Device.eager_load(:users, :points).where(users: { id: nil }, points: { point: 1..Float::INFINITY })<\/code><\/pre><\/div>\n\n\n\n<p>eager_load\u306e\u7b87\u6240\u306b\u3001\u305d\u306e\u307b\u304bincludes\u3060\u3068\u4e0a\u624b\u304f\u53d6\u5f97\u51fa\u6765\u307e\u3057\u305f\u304c\u3001joins\u306f\u60c5\u5831\u3092\u53d6\u5f97\u51fa\u6765\u305a0\u4ef6\u3001preload\u306f\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u30894\u3064\u306e\u7d50\u679c\u306e\u9055\u3044\u306f\u8abf\u3079\u308b\u3068\u3059\u3050\u306b\u51fa\u3066\u304f\u308b\u306e\u3067\u3059\u304c\u3001joins\u3060\u30510\u4ef6\u3068\u306a\u3063\u3066\u8fd4\u3063\u3066\u304f\u308b\u7406\u7531\u304c\u5f53\u521d\u5206\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002\uff08\u3053\u308c\u3092\u8aad\u3093\u3067\u3044\u308b\u65b9\u306f\u3059\u3050\u306b\u5206\u304b\u308a\u307e\u3059\u304b\uff1f\uff09<\/p>\n\n\n\n<div style=\"height:65px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u7b54\u3048\u306fjoins&nbsp;\u306fINNER JOIN\uff08<strong>\u5185\u90e8\u7d50\u5408<\/strong>\uff09\u306a\u306e\u304c\u7406\u7531\u3067\u3059\u3002<\/p>\n\n\n\n<p><strong>\u5185\u90e8\u7d50\u5408<\/strong>\u3068\u306f\u3001\u5404\u30c6\u30fc\u30d6\u30eb\u540c\u58eb\u3067\u95a2\u9023\u3065\u3051\u3089\u308c\u305fid\u304c\u4e00\u81f4\u3057\u3066\u3044\u308b\u3082\u306e\u3060\u3051\u3092\u4f7f\u3063\u3066\u65b0\u3057\u3044\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u308b\u3053\u3068\u3002<\/p>\n\n\n\n<p>\u3064\u307e\u308a\u3001\u4eca\u56de\u306e\u5834\u5408Device\u3068User\u3068Point\u306e\u305d\u308c\u305e\u308cid\u3092\u6301\u3063\u3066\u3044\u308b\u30c7\u30fc\u30bf\u3067\u65b0\u3057\u3044\u30c6\u30fc\u30d6\u30eb\u304c\u4f5c\u3089\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u2192\u3000\u305d\u306e\u305f\u3081\u3001where(users: { id: nil }\u3067User\u306eid\u3092\u6301\u305f\u306a\u3044Device\u306e\u30c7\u30fc\u30bf\u304c0\u4ef6\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3061\u306a\u307f\u306beager_load\u3068includes\u306f<strong>\u5de6\u5916\u90e8\u7d50\u5408<\/strong>\u3067\u3059\u306e\u3067\u3001Device\u306e\u5168\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u51fa\u3057\u3066User\u3068Point\u3092\u304f\u3063\u3064\u3051\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u2192\u3000\u305d\u306e\u305f\u3081\u3001where(users: { id: nil }\u3000\u3067\u3082Device\u306e\u30c7\u30fc\u30bf\u304c\u8fd4\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u3057\u3066\u6700\u5f8c\u306bpreload\u306f\u30a8\u30e9\u30fc\u3092\u8d77\u3053\u3059\u7406\u7531\u306f\u3001\u7d50\u5408\u5148\u306e\u30c6\u30fc\u30d6\u30eb\uff08users\u3084points\uff09\u3067\u7d5e\u308a\u8fbc\u3080\u3053\u3068\u304c\u305d\u3082\u305d\u3082\u51fa\u6765\u306a\u3044\u304b\u3089\u3067\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u904e\u53bb\u306b\u81ea\u5206\u304c\u30cf\u30de\u3063\u305f\u4e8b\u4f8b\u2461<\/h2>\n\n\n\n<p>\u2193AX-30\u3068\u3044\u3046\u30d1\u30bf\u30fc\u30f3\u756a\u53f7\u3092\u6301\u3064\u6a5f\u5668\u3092\u691c\u7d22(Device\u3068DeviceType\u306f\u591a\u5bfe1\u306e\u95a2\u4fc2)<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>Device.includes(:device_type).where(device_type: { pattern_number: &quot;AX-30&quot; })<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u308c\u3060\u3068\u30a8\u30e9\u30fc\u304c\u51fa\u307e\u3059\u3002\uff08ERROR: missing FROM-clause entry for table &#8220;device_type\u201d\uff09<\/p>\n\n\n\n<p>\u4f55\u6545\u3060\u304c\u5206\u304b\u308a\u307e\u3059\u304b\uff1f<\/p>\n\n\n\n<div style=\"height:65px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u3053\u306e\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u306b\u3088\u3063\u3066\u3059\u3050\u306b\u6c17\u304c\u4ed8\u3051\u308b\u4eba\u3082\u3044\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u304c\u3001<\/p>\n\n\n\n<p>includes(:device_type)\u3000\u306fdevice_type\u306e\u5358\u6570\u3067\u5408\u3063\u3066\u3044\u307e\u3059\u304c\u3001where(device_type\u3000\u304c\u9593\u9055\u3044\u3067\u3001<\/p>\n\n\n\n<p>\u6b63\u3057\u304f\u306fdevice_types\u3067\u3059\u3002<\/p>\n\n\n\n<p>includes\u306e\u7d50\u5408\u306fDevice\u304c\u591a\u3067DeviceType\u304c1\u306e\u69d8\u306b\u3001\u95a2\u4fc2\u6027\u306b\u3088\u3063\u3066device_type\u306e\u5358\u6570\u306b\u3082device_types\u306e\u8907\u6570\u306b\u3082\u306a\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u304c\u3001<\/p>\n\n\n\n<p>where\u306e\u6307\u5b9a\u5148\u306f<strong>\u30c6\u30fc\u30d6\u30eb<\/strong>\u3092\u6307\u5b9a\u3059\u308b\u305f\u3081\u3001<strong>\u7d76\u5bfe\u306b\u8907\u6570\u5f62<\/strong>\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u5927\u3057\u305f\u8a71\u3067\u306f\u306a\u3044\u3067\u3059\u304c\u3001\u4f55\u3068\u306a\u304f\u7d50\u5408\u3092\u884c\u306a\u3063\u3066\u3044\u308b\u3068\u6c17\u304c\u4ed8\u304b\u306a\u3044\u3053\u3068\u306a\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u601d\u3044\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>\u4ee5\u4e0aActiveRecord\u306b\u95a2\u3059\u308b\u8a71\u3067\u3057\u305f\u304c\u3001\u3053\u306e\u8a18\u4e8b\u3092\u6700\u5f8c\u307e\u3067\u8aad\u3093\u3067\u304f\u308c\u305f\u65b9\u306b\u306f\u3001\u5c11\u3057\u3067\u3082\u8eab\u306b\u3064\u3044\u305f\u77e5\u8b58\u304c\u3042\u308c\u3070\u5e78\u3044\u3067\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button aligncenter is-style-fill\"><a class=\"wp-block-button__link has-vivid-green-cyan-background-color has-background wp-element-button\" href=\"https:\/\/blog.fundely.co.jp\/tech\/?page_id=82&amp;preview=true\" style=\"border-radius:12px\">\u52df\u96c6\u8981\u9805\u304a\u3088\u3073\u30a8\u30f3\u30c8\u30ea\u30fc\u30d5\u30a9\u30fc\u30e0<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3002\u30c7\u30b6\u30a4\u30f3\u30fb\u30b7\u30b9\u30c6\u30e0\u5ba4\u306e\u5742\u4e95\u3067\u3059\u3002 \u4eca\u56de\u306f\u3001\u7686\u3055\u3093Rails\u3067\u304a\u99b4\u67d3\u307f\u306eActiveRecord\u306b\u3064\u3044\u3066\u8a71\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002 \u524d\u534a\u306f\u57fa\u672c\u306e\u8a71\u3067\u3001\u5f8c\u534a\u306f\u5b9f\u52d9\u3067\u4f7f\u3063\u305f\u4e8b\u3092\u8a71\u3057\u307e\u3059\u3002 ActiveRecord\u306e\u7406\u89e3\u306b [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[15,3],"tags":[],"class_list":["post-262","post","type-post","status-publish","format-standard","hentry","category-activerecord","category-rails"],"acf":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.fundely.co.jp\/tech\/wp-json\/wp\/v2\/posts\/262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.fundely.co.jp\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fundely.co.jp\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fundely.co.jp\/tech\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fundely.co.jp\/tech\/wp-json\/wp\/v2\/comments?post=262"}],"version-history":[{"count":69,"href":"https:\/\/blog.fundely.co.jp\/tech\/wp-json\/wp\/v2\/posts\/262\/revisions"}],"predecessor-version":[{"id":335,"href":"https:\/\/blog.fundely.co.jp\/tech\/wp-json\/wp\/v2\/posts\/262\/revisions\/335"}],"wp:attachment":[{"href":"https:\/\/blog.fundely.co.jp\/tech\/wp-json\/wp\/v2\/media?parent=262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fundely.co.jp\/tech\/wp-json\/wp\/v2\/categories?post=262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fundely.co.jp\/tech\/wp-json\/wp\/v2\/tags?post=262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}