{"id":20,"date":"2024-09-09T11:13:42","date_gmt":"2024-09-09T02:13:42","guid":{"rendered":"https:\/\/dexall.co.jp\/articles\/?p=20"},"modified":"2025-03-24T08:55:07","modified_gmt":"2025-03-23T23:55:07","slug":"ruby-on-rails-find_by-%e5%ae%8c%e5%85%a8%e3%82%ac%e3%82%a4%e3%83%89%ef%bc%9a%e4%bd%bf%e3%81%84%e6%96%b9%e3%81%8b%e3%82%89%e6%9c%80%e9%81%a9%e5%8c%96%e3%81%be%e3%81%a77%e3%81%a4%e3%81%ae%e9%87%8d","status":"publish","type":"post","link":"https:\/\/dexall.co.jp\/articles\/?p=20","title":{"rendered":"Ruby on Rails find_by \u5b8c\u5168\u30ac\u30a4\u30c9\uff1a\u4f7f\u3044\u65b9\u304b\u3089\u6700\u9069\u5316\u307e\u30677\u3064\u306e\u91cd\u8981\u30dd\u30a4\u30f3\u30c8"},"content":{"rendered":"\n<p>Ruby on Rails\u306e<code>find_by<\/code>\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u52b9\u7387\u7684\u306b\u30ec\u30b3\u30fc\u30c9\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306e\u5f37\u529b\u306a\u30c4\u30fc\u30eb\u3067\u3059\u3002<br>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001<code>find_by<\/code>\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u304b\u3089\u9ad8\u5ea6\u306a\u30c6\u30af\u30cb\u30c3\u30af\u3001\u305d\u3057\u3066\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3068\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u306e\u8003\u616e\u4e8b\u9805\u307e\u3067\u3001\u5305\u62ec\u7684\u306b\u89e3\u8aac\u3057\u307e\u3059\u3002<br>\u521d\u5fc3\u8005\u304b\u3089\u4e2d\u7d1a\u8005\u306eRails\u30a8\u30f3\u30b8\u30cb\u30a2\u307e\u3067\u3001<code>find_by<\/code>\u3092\u4f7f\u3044\u3053\u306a\u3059\u305f\u3081\u306e\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\u3092\u5b66\u3079\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u8a18\u4e8b\u3092\u8aad\u3093\u3060\u3089\u308f\u304b\u308b\u3053\u3068:<\/p>\n\n\n\n<div class=\"wp-block-sgb-block-simple sgb-box-simple sgb-box-simple--title-normal sgb-box-simple--with-border\"><div style=\"background-color:var(--wp--preset--color--sango-main);color:#FFF\" class=\"sgb-box-simple__title\">\u3053\u306e\u8a18\u4e8b\u3092\u901a\u3058\u3066\u7406\u89e3\u3067\u304d\u308b7\u3064\u306e\u3053\u3068<\/div><div class=\"sgb-box-simple__body\" style=\"border-color:var(--wp--preset--color--sango-main);background-color:#FFF\">\n<ul class=\"wp-block-list\">\n<li><code>find_by<\/code>\u30e1\u30bd\u30c3\u30c9\u306e\u57fa\u672c\u7684\u306a\u4f7f\u7528\u65b9\u6cd5<\/li>\n\n\n\n<li><code>find_by<\/code>\u3068<code>where<\/code>\u306e\u9055\u3044\u3068\u9069\u5207\u306a\u4f7f\u3044\u5206\u3051<\/li>\n\n\n\n<li>\u95a2\u9023\u4ed8\u3051\u3092\u5229\u7528\u3057\u305f<code>find_by<\/code>\u306e\u5fdc\u7528\u30c6\u30af\u30cb\u30c3\u30af<\/li>\n\n\n\n<li><code>find_by<\/code>\u4f7f\u7528\u6642\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6700\u9069\u5316\u65b9\u6cd5<\/li>\n\n\n\n<li>SQL\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u5bfe\u7b56\u306a\u3069\u306e\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u8003\u616e\u4e8b\u9805<\/li>\n\n\n\n<li>\u5927\u6587\u5b57\u5c0f\u6587\u5b57\u306e\u533a\u5225\u306b\u95a2\u3059\u308b\u6ce8\u610f\u70b9<\/li>\n\n\n\n<li><code>find_by<\/code>\u3092\u52b9\u679c\u7684\u306b\u4f7f\u7528\u3059\u308b\u305f\u3081\u306e7\u3064\u306e\u91cd\u8981\u30dd\u30a4\u30f3\u30c8<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"toc\"><br \/>\n<b>Warning<\/b>:  Undefined array key \"is_admin\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>116<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_category_top\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>121<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_top\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>128<\/b><br \/>\n    <div id=\"toc_container\" class=\"sgb-toc--bullets js-smooth-scroll\" data-dialog-title=\"\u76ee\u6b21\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">  <li class=\"first\">    <a href=\"#i-0\">1. \u306f\u3058\u3081\u306b\uff1afind_by\u30e1\u30bd\u30c3\u30c9\u306e\u6982\u8981<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-1\">1.1 find_by\u3068\u306f\u4f55\u304b<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-2\">1.2 find_by\u304cRails\u958b\u767a\u3067\u91cd\u8981\u306a\u7406\u7531<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-3\">2. find_by\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-4\">2.1 \u5358\u4e00\u306e\u6761\u4ef6\u3067\u30ec\u30b3\u30fc\u30c9\u3092\u691c\u7d22\u3059\u308b<\/a>      <\/li>      <li>        <a href=\"#i-5\">2.2 \u8907\u6570\u306e\u6761\u4ef6\u3092\u7d44\u307f\u5408\u308f\u305b\u308b<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-6\">2.3 \u623b\u308a\u5024\u306e\u7406\u89e3\uff1a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8 or nil<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-10\">3. find_by\u3068where\u306e\u9055\u3044<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-11\">3.1 \u5b9f\u884c\u7d50\u679c\u306e\u9055\u3044\uff1a\u5358\u4e00\u30aa\u30d6\u30b8\u30a7\u30af\u30c8 or ActiveRecord::Relation<\/a>      <\/li>      <li>        <a href=\"#i-14\">3.2 \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u9055\u3044<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-17\">3.3 \u4f7f\u3044\u5206\u3051\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-22\">4. find_by\u306e\u5fdc\u7528\u30c6\u30af\u30cb\u30c3\u30af<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-23\">4.1 \u95a2\u9023\u4ed8\u3051\u3092\u5229\u7528\u3057\u305ffind_by<\/a>      <\/li>      <li>        <a href=\"#i-24\">4.2 \u30b9\u30b3\u30fc\u30d7\u3068\u306e\u7d44\u307f\u5408\u308f\u305b<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-25\">4.3 find_by!\u306b\u3088\u308b\u4f8b\u5916\u51e6\u7406<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-26\">5. \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u8003\u616e\u3057\u305ffind_by\u306e\u4f7f\u7528\u65b9\u6cd5<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-27\">5.1 \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u91cd\u8981\u6027<\/a>      <\/li>      <li>        <a href=\"#i-28\">5.2 N+1\u554f\u984c\u306e\u56de\u907f<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-29\">5.3 \u5927\u898f\u6a21\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3067\u306e\u6700\u9069\u5316\u30c6\u30af\u30cb\u30c3\u30af<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-34\">6. find_by\u306e\u6ce8\u610f\u70b9\u3068\u5236\u9650\u4e8b\u9805<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-35\">6.1 SQL\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u5bfe\u7b56<\/a>      <\/li>      <li>        <a href=\"#i-39\">6.2 \u5927\u6587\u5b57\u5c0f\u6587\u5b57\u306e\u533a\u5225<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-43\">6.3 \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u30dc\u30c8\u30eb\u30cd\u30c3\u30af<\/a>      <\/li>    <\/ul>  <\/li>  <li class=\"last\">    <a href=\"#i-48\">7. \u307e\u3068\u3081\uff1afind_by\u3092\u4f7f\u3044\u3053\u306a\u3059\u305f\u3081\u306e7\u3064\u306e\u91cd\u8981\u30dd\u30a4\u30f3\u30c8<\/a>  <\/li><\/ul>\n      <a href=\"#\" class=\"sgb-toc-button js-toc-button\" rel=\"nofollow\" data-open-dialog=\"true\"><i class=\"fa fa-list\"><\/i><span class=\"sgb-toc-button__text\">\u76ee\u6b21\u3078<\/span><\/a>\n    <\/div><\/div><h2 class=\"wp-block-heading\" id=\"i-0\">1. \u306f\u3058\u3081\u306b\uff1afind_by\u30e1\u30bd\u30c3\u30c9\u306e\u6982\u8981<\/h2>\n\n\n\n<p>Ruby on Rails\u306e\u958b\u767a\u306b\u304a\u3044\u3066\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u306e\u3084\u308a\u53d6\u308a\u306f\u975e\u5e38\u306b\u91cd\u8981\u306a\u90e8\u5206\u3092\u5360\u3081\u3066\u3044\u307e\u3059\u3002<br>ActiveRecord\u306f\u3001\u305d\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u64cd\u4f5c\u3092\u7c21\u5358\u304b\u3064\u52b9\u7387\u7684\u306b\u884c\u3046\u305f\u3081\u306e\u4fbf\u5229\u306a\u30c4\u30fc\u30eb\uff08\u30e1\u30bd\u30c3\u30c9\uff09\u3092\u6570\u591a\u304f\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002<br>\u305d\u306e\u4e2d\u3067\u3082\u3001<code>find_by<\/code>\u30e1\u30bd\u30c3\u30c9\u306f\u7279\u306b\u91cd\u8981\u306a\u5f79\u5272\u3092\u679c\u305f\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-1\">1.1 find_by\u3068\u306f\u4f55\u304b<\/h3>\n\n\n\n<p><code>find_by<\/code>\u306f\u3001ActiveRecord\u304c\u63d0\u4f9b\u3059\u308b\u30af\u30a8\u30ea\u30e1\u30bd\u30c3\u30c9\u306e1\u3064\u3067\u3059\u3002<br>\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u6761\u4ef6\u306b\u4e00\u81f4\u3059\u308b\u6700\u521d\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u8fd4\u3057\u307e\u3059\u3002\u57fa\u672c\u7684\u306a\u4f7f\u7528\u65b9\u6cd5\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u57fa\u672c\u7684\u306a\u4f7f\u7528\u65b9\u6cd5\nresult = Model.find_by(\u6761\u4ef6)\n\n# \u5177\u4f53\u7684\u306a\u4f8b\nuser = User.find_by(email: 'example@example.com')<\/pre>\n\n\n\n<div class=\"wp-block-sgb-block-simple sgb-box-simple sgb-box-simple--title-normal sgb-box-simple--with-border\"><div style=\"background-color:var(--wp--preset--color--sango-main);color:#FFF\" class=\"sgb-box-simple__title\"><code>find_by <\/code>\u30e1\u30bd\u30c3\u30c9\u306e3\u3064\u306e\u4e3b\u306a\u7279\u5fb4<\/div><div class=\"sgb-box-simple__body\" style=\"border-color:var(--wp--preset--color--sango-main);background-color:#FFF\">\n<ol class=\"wp-block-list\">\n<li>\u5358\u4e00\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3059<\/li>\n\n\n\n<li>\u6761\u4ef6\u306b\u4e00\u81f4\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u304c\u306a\u3044\u5834\u5408\u306f<code>nil<\/code>\u3092\u8fd4\u3059<\/li>\n\n\n\n<li>\u8907\u6570\u306e\u6761\u4ef6\u3092\u6307\u5b9a\u53ef\u80fd<\/li>\n<\/ol>\n<\/div><\/div>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8907\u6570\u306e\u6761\u4ef6\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">product = Product.find_by(name: 'Ruby Book', category: 'Programming')<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-2\">1.2 find_by\u304cRails\u958b\u767a\u3067\u91cd\u8981\u306a\u7406\u7531<\/h3>\n\n\n\n<p><code>find_by<\/code>\u30e1\u30bd\u30c3\u30c9\u306f\u3001Rails\u958b\u767a\u306b\u304a\u3044\u3066\u4e0b\u8a18\u306e\u7406\u7531\u304b\u3089\u975e\u5e38\u306b\u91cd\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-sgb-block-simple sgb-box-simple sgb-box-simple--title-normal sgb-box-simple--with-border\"><div style=\"background-color:var(--wp--preset--color--sango-main);color:#FFF\" class=\"sgb-box-simple__title\"><code>find_by<\/code> \u30e1\u30bd\u30c3\u30c9\u304c\u91cd\u8981\u3067\u3042\u308b3\u3064\u306e\u7406\u7531<\/div><div class=\"sgb-box-simple__body\" style=\"border-color:var(--wp--preset--color--sango-main);background-color:#FFF\">\n<ol class=\"wp-block-list\">\n<li><strong>\u30b3\u30fc\u30c9\u306e\u53ef\u8aad\u6027\u5411\u4e0a<\/strong>\uff1a<code>find_by<\/code>\u306f\u76f4\u611f\u7684\u3067\u8aad\u307f\u3084\u3059\u3044\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u6761\u4ef6\u3092\u30cf\u30c3\u30b7\u30e5\u3067\u6307\u5b9a\u3059\u308b\u305f\u3081\u3001\u4f55\u3092\u691c\u7d22\u3057\u3066\u3044\u308b\u306e\u304b\u304c\u4e00\u76ee\u3067\u5206\u304b\u308a\u307e\u3059\u3002<\/li>\n\n\n\n<li><strong>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30af\u30a8\u30ea\u306e\u52b9\u7387\u5316<\/strong>\uff1a<code>find_by<\/code>\u306f\u6700\u521d\u306b\u4e00\u81f4\u3057\u305f\u30ec\u30b3\u30fc\u30c9\u3092\u8fd4\u3059\u305f\u3081\u3001\u5fc5\u8981\u4ee5\u4e0a\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u307e\u305b\u3093\u3002\u7279\u306b\u5927\u898f\u6a21\u306a\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u6271\u3046\u969b\u306b\u3001\u975e\u5e38\u306b\u52b9\u529b\u3092\u767a\u63ee\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li><strong>\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u306e\u7c21\u7d20\u5316<\/strong>\uff1a<code>find_by<\/code>\u306f\u6761\u4ef6\u306b\u4e00\u81f4\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u304c\u306a\u3044\u5834\u5408\u306b<code>nil<\/code>\u3092\u8fd4\u3059\u305f\u3081\u3001<code>nil<\/code>\u30c1\u30a7\u30c3\u30af\u3092\u884c\u3046\u3060\u3051\u3067\u7c21\u5358\u306b\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u304c\u3067\u304d\u307e\u3059\u3002<\/li>\n<\/ol>\n<\/div><\/div>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">user = User.find_by(email: 'example@example.com')\nif user.nil?\n  puts \"\u30e6\u30fc\u30b6\u30fc\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\"\nelse\n  puts \"\u30e6\u30fc\u30b6\u30fc\u304c\u898b\u3064\u304b\u308a\u307e\u3057\u305f: #{user.name}\"\nend<\/pre>\n\n\n\n<p>\u521d\u5fc3\u8005\u301c\u4e2d\u7d1a\u8005\u306e\u30a8\u30f3\u30b8\u30cb\u30a2\u306b\u3068\u3063\u3066\u3001<code>find_by<\/code>\u306f\u3088\u304f\u76ee\u306b\u3059\u308b\u8a18\u8ff0\u3067\u306f\u3042\u308a\u307e\u3059\u304c\u3001\u4fbf\u5229\u306a\u6a5f\u80fd\u3092\u63d0\u4f9b\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<br>\u57fa\u672c\u7684\u306a\u30c7\u30fc\u30bf\u53d6\u5f97\u304b\u3089\u8907\u96d1\u306a\u6761\u4ef6\u6307\u5b9a\u307e\u3067\u3001\u5e45\u5e83\u3044\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u306b\u5bfe\u5fdc\u3067\u304d\u308b\u67d4\u8edf\u6027\u3092\u6301\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001<code>find_by<\/code>\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3092\u3088\u308a\u8a73\u3057\u304f\u898b\u3066\u3044\u304d\u307e\u3059\u3002<br>\u69d8\u3005\u306a\u6761\u4ef6\u6307\u5b9a\u306e\u65b9\u6cd5\u3084\u3001\u623b\u308a\u5024\u306e\u6271\u3044\u65b9\u306b\u3064\u3044\u3066\u5b66\u3093\u3067\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-3\">2. find_by\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/h2>\n\n\n\n<p><code>find_by<\/code>\u30e1\u30bd\u30c3\u30c9\u306f\u3001ActiveRecord\u30e2\u30c7\u30eb\u306b\u5bfe\u3057\u3066\u7c21\u5358\u304b\u3064\u76f4\u611f\u7684\u306b\u4f7f\u7528\u3067\u304d\u308b\u30af\u30a8\u30ea\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001<code>find_by<\/code>\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3092\u3001\u5358\u4e00\u6761\u4ef6\u3067\u306e\u691c\u7d22\u3001\u8907\u6570\u6761\u4ef6\u306e\u7d44\u307f\u5408\u308f\u305b\u3001\u305d\u3057\u3066\u623b\u308a\u5024\u306e\u7406\u89e3\u3068\u3044\u30463\u3064\u306e\u89b3\u70b9\u304b\u3089\u8a73\u3057\u304f\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-4\">2.1 \u5358\u4e00\u306e\u6761\u4ef6\u3067\u30ec\u30b3\u30fc\u30c9\u3092\u691c\u7d22\u3059\u308b<\/h3>\n\n\n\n<p><code>find_by<\/code>\u306e\u6700\u3082\u57fa\u672c\u7684\u306a\u4f7f\u7528\u65b9\u6cd5\u306f\u3001\u5358\u4e00\u306e\u6761\u4ef6\u3067\u30ec\u30b3\u30fc\u30c9\u3092\u691c\u7d22\u3059\u308b\u3053\u3068\u3067\u3059\u3002<br>\u57fa\u672c\u7684\u306a\u69cb\u6587\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Model.find_by(\u6761\u4ef6)<\/pre>\n\n\n\n<p>\u5177\u4f53\u7684\u306a\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3067\u30e6\u30fc\u30b6\u30fc\u3092\u691c\u7d22\nuser = User.find_by(email: 'example@example.com')\n\n# \u540d\u524d\u3067\u5546\u54c1\u3092\u691c\u7d22\nproduct = Product.find_by(name: 'Ruby Book')<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u4f8b\u3067\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u6761\u4ef6\uff08email\u307e\u305f\u306fname\uff09\u306b\u4e00\u81f4\u3059\u308b\u6700\u521d\u306e\u30ec\u30b3\u30fc\u30c9\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-5\">2.2 \u8907\u6570\u306e\u6761\u4ef6\u3092\u7d44\u307f\u5408\u308f\u305b\u308b<\/h3>\n\n\n\n<p><code>find_by<\/code>\u306e\u7279\u5fb4\u306e1\u3064\u306f\u3001\u8907\u6570\u306e\u6761\u4ef6\u3092\u7c21\u5358\u306b\u7d44\u307f\u5408\u308f\u305b\u3089\u308c\u308b\u3053\u3068\u3067\u3059\u3002<br>\u8907\u6570\u306e\u6761\u4ef6\u306f\u3001\u30cf\u30c3\u30b7\u30e5\u5f62\u5f0f\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Model.find_by(\u6761\u4ef61: \u50241, \u6761\u4ef62: \u50242)<\/pre>\n\n\n\n<p>\u5177\u4f53\u7684\u306a\u4f7f\u7528\u4f8b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u59d3\u3068\u540d\u3067\u30e6\u30fc\u30b6\u30fc\u3092\u691c\u7d22\nuser = User.find_by(first_name: 'John', last_name: 'Doe')\n\n# \u30b9\u30c6\u30fc\u30bf\u30b9\u3068\u5408\u8a08\u91d1\u984d\u3067\u6ce8\u6587\u3092\u691c\u7d22\norder = Order.find_by(status: 'shipped', total: 100)<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u4f8b\u3067\u306f\u3001\u3059\u3079\u3066\u306e\u6761\u4ef6\u306b\u4e00\u81f4\u3059\u308b\u6700\u521d\u306e\u30ec\u30b3\u30fc\u30c9\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002<br>\u8907\u6570\u306e\u6761\u4ef6\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u3088\u308a\u7cbe\u5bc6\u306a\u691c\u7d22\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-6\">2.3 \u623b\u308a\u5024\u306e\u7406\u89e3\uff1a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8 or nil<\/h3>\n\n\n\n<p><code>find_by<\/code>\u30e1\u30bd\u30c3\u30c9\u306e\u623b\u308a\u5024\u3092\u6b63\u3057\u304f\u7406\u89e3\u3057\u3001\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3084\u6761\u4ef6\u5206\u5c90\u3092\u9069\u5207\u306b\u51e6\u7406\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u4e00\u81f4\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u304c\u3042\u308b\u5834\u5408<\/strong><br>\u6700\u521d\u306b\u4e00\u81f4\u3057\u305fActiveRecord\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002<\/li>\n\n\n\n<li><strong>\u4e00\u81f4\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u304c\u306a\u3044\u5834\u5408<\/strong><br><code>nil<\/code>\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u3053\u306e\u7279\u6027\u3092\u8e0f\u307e\u3048\u3001<code>nil<\/code>\u3092\u9069\u5207\u306b\u51e6\u7406\u3059\u308b\u65b9\u6cd5\u3092\u3044\u304f\u3064\u304b\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-7\">if\u6587\u306b\u3088\u308b\u6761\u4ef6\u5206\u5c90<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">user = User.find_by(email: 'example@example.com')\nif user\n  puts \"\u30e6\u30fc\u30b6\u30fc\u304c\u898b\u3064\u304b\u308a\u307e\u3057\u305f: #{user.name}\"\nelse\n  puts \"\u30e6\u30fc\u30b6\u30fc\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\"\nend<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-8\">&amp;.\u6f14\u7b97\u5b50\uff08Safe Navigation Operator\uff09\u306e\u4f7f\u7528<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">user = User.find_by(email: 'example@example.com')\nputs \"\u30e6\u30fc\u30b6\u30fc\u540d: #{user&amp;.name}\"  # user\u304cnil\u306e\u5834\u5408\u3067\u3082\u30a8\u30e9\u30fc\u306b\u306a\u3089\u306a\u3044<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-9\"><code>find_by!<\/code>\u306b\u3088\u308b\u4f8b\u5916\u767a\u751f<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">begin\n  user = User.find_by!(email: 'example@example.com')\n  puts \"\u30e6\u30fc\u30b6\u30fc\u304c\u898b\u3064\u304b\u308a\u307e\u3057\u305f: #{user.name}\"\nrescue ActiveRecord::RecordNotFound\n  puts \"\u30e6\u30fc\u30b6\u30fc\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\"\nend<\/pre>\n\n\n\n<p><code>find_by!<\/code>\u306f\u3001\u30ec\u30b3\u30fc\u30c9\u304c\u898b\u3064\u304b\u3089\u306a\u3044\u5834\u5408\u306b<code>ActiveRecord::RecordNotFound<\/code>\u4f8b\u5916\u3092\u767a\u751f\u3055\u305b\u307e\u3059\u3002<br>\u3053\u308c\u306b\u3088\u308a\u3001\u4f8b\u5916\u51e6\u7406\u3092\u4f7f\u3063\u3066\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u304c<code>find_by<\/code>\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3067\u3059\u3002<br>\u5358\u4e00\u6761\u4ef6\u3067\u306e\u691c\u7d22\u3001\u8907\u6570\u6761\u4ef6\u306e\u7d44\u307f\u5408\u308f\u305b\u3001\u305d\u3057\u3066\u623b\u308a\u5024\u306e\u9069\u5207\u306a\u51e6\u7406\u65b9\u6cd5\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u3067\u3001<code>find_by<\/code>\u3092\u52b9\u679c\u7684\u306b\u6d3b\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<br>\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001<code>find_by<\/code>\u3068<code>where<\/code>\u30e1\u30bd\u30c3\u30c9\u306e\u9055\u3044\u306b\u3064\u3044\u3066\u8a73\u3057\u304f\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-10\">3. find_by\u3068where\u306e\u9055\u3044<\/h2>\n\n\n\n<p>ActiveRecord\u306b\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u30ec\u30b3\u30fc\u30c9\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306e\u69d8\u3005\u306a\u30e1\u30bd\u30c3\u30c9\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br>\u305d\u306e\u4e2d\u3067\u3082<code>find_by<\/code>\u3068<code>where<\/code>\u306f\u983b\u7e41\u306b\u4f7f\u7528\u3055\u308c\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u304c\u3001\u4e00\u898b\u4f3c\u3066\u3044\u308b\u3088\u3046\u306b\u898b\u3048\u3066\u3001\u5b9f\u969b\u306b\u306f\u304b\u306a\u308a\u91cd\u8981\u3068\u306a\u308b\u9055\u3044\u304c\u3044\u304f\u3064\u304b\u5b58\u5728\u3057\u307e\u3059\u3002<br>\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001<code>find_by<\/code>\u3068<code>where<\/code>\u306e\u9055\u3044\u3092\u8a73\u3057\u304f\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-11\">3.1 \u5b9f\u884c\u7d50\u679c\u306e\u9055\u3044\uff1a\u5358\u4e00\u30aa\u30d6\u30b8\u30a7\u30af\u30c8 or ActiveRecord::Relation<\/h3>\n\n\n\n<p><code>find_by<\/code>\u3068<code>where<\/code>\u306e\u6700\u3082\u5927\u304d\u306a\u9055\u3044\u306f\u3001\u305d\u308c\u305e\u308c\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u8fd4\u3059\u7d50\u679c\u306e\u5f62\u5f0f\u3067\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-12\"><strong>find_by<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5358\u4e00\u306eActiveRecord\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li>\u6761\u4ef6\u306b\u4e00\u81f4\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u304c\u306a\u3044\u5834\u5408\u306f<code>nil<\/code>\u3092\u8fd4\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   user = User.find_by(email: 'example@example.com')\n   # =&gt; #&lt;User id: 1, email: \"example@example.com\", ...&gt; \u307e\u305f\u306f nil<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-13\"><strong>where<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>ActiveRecord::Relation\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li>\u6761\u4ef6\u306b\u4e00\u81f4\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u304c\u306a\u3044\u5834\u5408\u306f\u7a7a\u306e\u914d\u5217\u3092\u8fd4\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   users = User.where(status: 'active')\n   # =&gt; #&lt;ActiveRecord::Relation [#&lt;User id: 1, status: \"active\", ...&gt;, #&lt;User id: 2, status: \"active\", ...&gt;]&gt;<\/pre>\n\n\n\n<p>\u4e0a\u8a18\u306e <code>find_by<\/code> \u3068 <code>where<\/code> \u306e\u9055\u3044\u306f\u3001\u305d\u306e\u5f8c\u306e\u51e6\u7406\u306b\u5927\u304d\u306a\u5f71\u97ff\u3092\u4e0e\u3048\u307e\u3059\u3002<br><code>find_by<\/code>\u306e\u7d50\u679c\u306b\u5bfe\u3057\u3066\u306f\u76f4\u63a5\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u305b\u307e\u3059\u304c\u3001<code>where<\/code>\u306e\u7d50\u679c\u306b\u5bfe\u3057\u3066\u306f\u3055\u3089\u306a\u308b\u7d5e\u308a\u8fbc\u307f\u3084\u51e6\u7406\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-14\">3.2 \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u9055\u3044<\/h3>\n\n\n\n<p>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u89b3\u70b9\u304b\u3089\u3082\u3001<code>find_by<\/code>\u3068<code>where<\/code>\u306b\u306f\u9055\u3044\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-15\"><strong>find_by<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5358\u4e00\u30ec\u30b3\u30fc\u30c9\u306e\u53d6\u5f97\u306b\u6700\u9069\u5316\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/li>\n\n\n\n<li>\u5185\u90e8\u7684\u306b<code>LIMIT 1<\/code>\u304c\u81ea\u52d5\u7684\u306b\u4ed8\u52a0\u3055\u308c\u308b\u305f\u3081\u3001\u6700\u521d\u306b\u4e00\u81f4\u3057\u305f\u30ec\u30b3\u30fc\u30c9\u306e\u307f\u3092\u8fd4\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#\u767a\u884c\u3055\u308c\u308bSQL\u4f8b\n   SELECT * FROM users WHERE email = 'example@example.com' LIMIT 1<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-16\"><strong>where<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8907\u6570\u30ec\u30b3\u30fc\u30c9\u306e\u53d6\u5f97\u3084\u3001\u3055\u3089\u306a\u308b\u7d5e\u308a\u8fbc\u307f\u306b\u9069\u3057\u3066\u3044\u307e\u3059\u3002<\/li>\n\n\n\n<li>\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u3059\u3079\u3066\u306e\u4e00\u81f4\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#\u767a\u884c\u3055\u308c\u308bSQL\u4f8b\n   SELECT * FROM users WHERE status = 'active'<\/pre>\n\n\n\n<p>\u5927\u898f\u6a21\u306a\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u6271\u3046\u5834\u5408\u3001<code>find_by<\/code>\u306f\u5fc5\u8981\u6700\u5c0f\u9650\u306e\u30c7\u30fc\u30bf\u306e\u307f\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u3001<code>where<\/code>\u3088\u308a\u3082\u52b9\u7387\u7684\u306b\u691c\u7d22\u3067\u304d\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-17\">3.3 \u4f7f\u3044\u5206\u3051\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/h3>\n\n\n\n<p><code>find_by<\/code>\u3068<code>where<\/code>\u306e\u7279\u6027\u3092\u7406\u89e3\u3057\u305f\u4e0a\u3067\u3001\u9069\u5207\u306b\u4f7f\u3044\u5206\u3051\u308b\u3053\u3068\u306b\u3088\u308a\u51e6\u7406\u52b9\u7387\u304c\u5927\u304d\u304f\u5909\u308f\u3063\u3066\u304d\u307e\u3059\u3002<br>\u4ee5\u4e0b\u306b\u3001\u4f7f\u3044\u5206\u3051\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-18\"><strong>\u5358\u4e00\u30ec\u30b3\u30fc\u30c9\u306e\u53d6\u5f97<\/strong><\/h4>\n\n\n\n<p>\u5358\u4e00\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u306f<code>find_by<\/code>\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   user = User.find_by(email: 'example@example.com')<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-19\"><strong>\u8907\u6570\u30ec\u30b3\u30fc\u30c9\u306e\u53d6\u5f97\u3084\u8ffd\u52a0\u306e\u7d5e\u308a\u8fbc\u307f<\/strong><\/h4>\n\n\n\n<p>\u8907\u6570\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u3084\u3001\u305d\u306e\u5f8c\u306e\u51e6\u7406\u3067\u7d50\u679c\u3092\u3055\u3089\u306b\u7d5e\u308a\u8fbc\u3080\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306f<code>where<\/code>\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   active_users = User.where(status: 'active').order(:created_at)<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-20\"><strong>nil\u306e\u6271\u3044\u3068\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>nil<\/code>\u3092\u8fd4\u3059\u52d5\u4f5c\u304c\u671b\u307e\u3057\u3044\u5834\u5408\u306f<code>find_by<\/code>\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li>\u30ec\u30b3\u30fc\u30c9\u304c\u5b58\u5728\u3057\u306a\u3044\u969b\u306b\u4f8b\u5916\u3092\u767a\u751f\u3055\u305b\u305f\u3044\u5834\u5408\u306f<code>find_by!<\/code>\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li>\u7a7a\u306e\u7d50\u679c\u30bb\u30c3\u30c8\uff08\u7a7a\u914d\u5217\u306a\u3069\uff09\u3092\u8fd4\u3059\u52d5\u4f5c\u304c\u671b\u307e\u3057\u3044\u5834\u5408\u306f<code>where<\/code>\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-21\"><strong>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u6700\u9069\u5316<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5927\u898f\u6a21\u306a\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u304b\u3089\u5358\u4e00\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u306f<code>find_by<\/code>\u306e\u65b9\u304c\u52b9\u7387\u7684\u3067\u3059\u3002<\/li>\n\n\n\n<li>\u8907\u6570\u306e\u30ec\u30b3\u30fc\u30c9\u306b\u5bfe\u3057\u3066\u4e00\u62ec\u51e6\u7406\u3092\u884c\u3046\u5834\u5408\u306f<code>where<\/code>\u3092\u4f7f\u7528\u3057\u3001\u5fc5\u8981\u306b\u5fdc\u3058\u3066<code>limit<\/code>\u3092\u7d44\u307f\u5408\u308f\u305b\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u826f\u3044\u4f8b\uff1a\u5358\u4e00\u30ec\u30b3\u30fc\u30c9\u306e\u53d6\u5f97\nuser = User.find_by(email: 'example@example.com')\n\n# \u826f\u3044\u4f8b\uff1a\u8907\u6570\u30ec\u30b3\u30fc\u30c9\u306e\u53d6\u5f97\u3068\u8ffd\u52a0\u306e\u7d5e\u308a\u8fbc\u307f\nrecent_active_users = User.where(status: 'active').where('last_login_at &gt; ?', 1.week.ago).limit(10)\n\n# \u6ce8\u610f\u304c\u5fc5\u8981\u306a\u4f8b\uff1a\u4e0d\u5fc5\u8981\u306bwhere\u3092\u4f7f\u7528\nuser = User.where(email: 'example@example.com').first # find_by\u306e\u65b9\u304c\u9069\u5207<\/pre>\n\n\n\n<p><code>find_by<\/code>\u3068<code>where<\/code>\u306e\u9069\u5207\u306a\u4f7f\u3044\u5206\u3051\u306f\u3001\u30b3\u30fc\u30c9\u306e\u53ef\u8aad\u6027\u3001\u4fdd\u5b88\u6027\u3001\u305d\u3057\u3066\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u5411\u4e0a\u306b\u3064\u306a\u304c\u308a\u307e\u3059\u3002<br>\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001<code>find_by<\/code>\u306e\u3088\u308a\u9ad8\u5ea6\u306a\u4f7f\u7528\u65b9\u6cd5\u306b\u3064\u3044\u3066\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-22\">4. find_by\u306e\u5fdc\u7528\u30c6\u30af\u30cb\u30c3\u30af<\/h2>\n\n\n\n<p><code>find_by<\/code>\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u57fa\u672c\u7684\u306a\u4f7f\u7528\u65b9\u6cd5\u3060\u3051\u3067\u306a\u304f\u3001\u3088\u308a\u9ad8\u5ea6\u306a\u6280\u6cd5\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u3055\u3089\u306b\u67d4\u8edf\u3067\u5f37\u529b\u306a\u30af\u30a8\u30ea\u3092\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<br>\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001<code>find_by<\/code>\u306e\u5fdc\u7528\u30c6\u30af\u30cb\u30c3\u30af\u3068\u3057\u3066\u3001\u95a2\u9023\u4ed8\u3051\u306e\u5229\u7528\u3001\u30b9\u30b3\u30fc\u30d7\u3068\u306e\u7d44\u307f\u5408\u308f\u305b\u3001\u305d\u3057\u3066<code>find_by!<\/code>\u306b\u3088\u308b\u4f8b\u5916\u51e6\u7406\u306b\u3064\u3044\u3066\u8a73\u3057\u304f\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-23\">4.1 \u95a2\u9023\u4ed8\u3051\u3092\u5229\u7528\u3057\u305ffind_by<\/h3>\n\n\n\n<p>ActiveRecord\u306e\u5f37\u529b\u306a\u6a5f\u80fd\u306e\u4e00\u3064\u306b\u3001\u30e2\u30c7\u30eb\u9593\u306e\u95a2\u9023\u4ed8\u3051\u304c\u3042\u308a\u307e\u3059\u3002<code>find_by<\/code>\u306f\u3001\u3053\u308c\u3089\u306e\u95a2\u9023\u4ed8\u3051\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3001\u8907\u96d1\u306a\u691c\u7d22\u3092\u7c21\u6f54\u306b\u8868\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001\u30e6\u30fc\u30b6\u30fc\u306e\u6295\u7a3f\u3092\u691c\u7d22\u3059\u308b\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">user = User.find_by(email: 'example@example.com')\npost = user.posts.find_by(title: 'Ruby on Rails\u5165\u9580')<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001\u7279\u5b9a\u306e\u30e6\u30fc\u30b6\u30fc\u306e\u6295\u7a3f\u306e\u4e2d\u304b\u3089\u3001\u30bf\u30a4\u30c8\u30eb\u304c\u300cRuby on Rails\u5165\u9580\u300d\u3067\u3042\u308b\u6700\u521d\u306e\u6295\u7a3f\u3092\u53d6\u5f97\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305f\u3001\u8907\u6570\u306e\u95a2\u9023\u4ed8\u3051\u3092\u7d4c\u7531\u3057\u305f\u691c\u7d22\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">company = Company.find_by(name: 'Dexall')\nemployee = company.departments.find_by(name: '\u958b\u767a\u90e8').employees.find_by(role: '\u30a8\u30f3\u30b8\u30cb\u30a2')<\/pre>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306b\u3001\u95a2\u9023\u4ed8\u3051\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u8907\u96d1\u306a\u6761\u4ef6\u3092\u76f4\u611f\u7684\u306b\u8868\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-24\">4.2 \u30b9\u30b3\u30fc\u30d7\u3068\u306e\u7d44\u307f\u5408\u308f\u305b<\/h3>\n\n\n\n<p>\u30b9\u30b3\u30fc\u30d7\u306f\u3001\u983b\u7e41\u306b\u4f7f\u7528\u3059\u308b\u30af\u30a8\u30ea\u6761\u4ef6\u3092\u30e2\u30c7\u30eb\u5185\u306b\u30ab\u30d7\u30bb\u30eb\u5316\u3059\u308b\u6a5f\u80fd\u3067\u3059\u3002<br><code>find_by<\/code>\u306f\u3053\u306e\u30b9\u30b3\u30fc\u30d7\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3001\u30b3\u30fc\u30c9\u306e\u53ef\u8aad\u6027\u3068\u518d\u5229\u7528\u6027\u3092\u9ad8\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u30e6\u30fc\u30b6\u30fc\u306e\u4e2d\u304b\u3089\u7279\u5b9a\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3092\u6301\u3064\u30e6\u30fc\u30b6\u30fc\u3092\u691c\u7d22\u3059\u308b\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class User &lt; ApplicationRecord\n  scope :active, -&gt; { where(status: 'active') }\nend\n\nUser.active.find_by(email: 'example@example.com')<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>active<\/code>\u30b9\u30b3\u30fc\u30d7\u3068<code>find_by<\/code>\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u30e6\u30fc\u30b6\u30fc\u306e\u4e2d\u304b\u3089\u7279\u5b9a\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3092\u6301\u3064\u30e6\u30fc\u30b6\u30fc\u3092\u7c21\u6f54\u306b\u691c\u7d22\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30b9\u30b3\u30fc\u30d7\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u8907\u96d1\u306a\u6761\u4ef6\u3092\u518d\u5229\u7528\u53ef\u80fd\u306a\u5f62\u3067\u5b9a\u7fa9\u3057\u3001<code>find_by<\/code>\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u67d4\u8edf\u306a\u691c\u7d22\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-25\">4.3 find_by!\u306b\u3088\u308b\u4f8b\u5916\u51e6\u7406<\/h3>\n\n\n\n<p><code>find_by<\/code>\u306e\u7279\u6b8a\u306a\u5f62\u3068\u3057\u3066<code>find_by!<\/code>\u304c\u3042\u308a\u307e\u3059\u3002<br>\u901a\u5e38\u306e<code>find_by<\/code>\u304c\u6761\u4ef6\u306b\u4e00\u81f4\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u304c\u898b\u3064\u304b\u3089\u306a\u3044\u5834\u5408\u306b<code>nil<\/code>\u3092\u8fd4\u3059\u306e\u306b\u5bfe\u3057\u3001<code>find_by!<\/code>\u306f<code>ActiveRecord::RecordNotFound<\/code>\u4f8b\u5916\u3092\u767a\u751f\u3055\u305b\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">begin\n  user = User.find_by!(email: 'non_existent@example.com')\nrescue ActiveRecord::RecordNotFound\n  puts \"\u6307\u5b9a\u3055\u308c\u305f\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306e\u30e6\u30fc\u30b6\u30fc\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3002\"\nend<\/pre>\n\n\n\n<p><code>find_by!<\/code>\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30ec\u30b3\u30fc\u30c9\u304c\u898b\u3064\u304b\u3089\u306a\u3044\u5834\u5408\u306e\u51e6\u7406\u3092\u4f8b\u5916\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3068\u3057\u3066\u8a18\u8ff0\u3067\u304d\u307e\u3059\u3002<br>\u3053\u308c\u306f\u3001\u30ec\u30b3\u30fc\u30c9\u304c\u5fc5\u305a\u5b58\u5728\u3059\u3079\u304d\u5834\u5408\u3084\u3001\u30ec\u30b3\u30fc\u30c9\u304c\u898b\u3064\u304b\u3089\u306a\u3044\u5834\u5408\u306b\u7279\u5225\u306a\u51e6\u7406\u3092\u884c\u3044\u305f\u3044\u5834\u5408\u306b\u7279\u306b\u6709\u7528\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u5fdc\u7528\u30c6\u30af\u30cb\u30c3\u30af\u3092\u4f7f\u7528\u3059\u308b\u969b\u306b\u306f\u4ee5\u4e0b\u306e\u6ce8\u610f\u70b9\u306b\u6c17\u3092\u3064\u3051\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<div class=\"wp-block-sgb-block-simple sgb-box-simple sgb-box-simple--title-normal sgb-box-simple--with-border\"><div style=\"background-color:var(--wp--preset--color--sango-main);color:#FFF\" class=\"sgb-box-simple__title\"><code>find_by<\/code> \u3092\u5229\u7528\u3059\u308b\u969b\u306e3\u3064\u306e\u6ce8\u610f\u70b9<\/div><div class=\"sgb-box-simple__body\" style=\"border-color:var(--wp--preset--color--sango-main);background-color:#FFF\">\n<ol class=\"wp-block-list\">\n<li><strong>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3078\u306e\u5f71\u97ff<\/strong>: \u95a2\u9023\u4ed8\u3051\u3084\u30b9\u30b3\u30fc\u30d7\u3092\u591a\u7528\u3059\u308b\u3068\u3001\u8907\u96d1\u306aSQL\u30af\u30a8\u30ea\u304c\u751f\u6210\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u751f\u6210\u3055\u308c\u308bSQL\u3092\u78ba\u8a8d\u3057\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306b\u6ce8\u610f\u3092\u6255\u3044\u307e\u3057\u3087\u3046\u3002<\/li>\n\n\n\n<li><strong>\u9069\u5207\u306a\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u8a2d\u5b9a<\/strong>: \u7279\u306b\u95a2\u9023\u4ed8\u3051\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u9069\u5207\u306a\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u5927\u5e45\u306b\u5411\u4e0a\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/li>\n\n\n\n<li><strong>\u4f8b\u5916\u51e6\u7406\u306e\u9069\u5207\u306a\u4f7f\u7528<\/strong>: <code>find_by!<\/code>\u3092\u4f7f\u7528\u3059\u308b\u969b\u306f\u3001\u4f8b\u5916\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u3092\u5e38\u306b\u8003\u616e\u3057\u3001\u9069\u5207\u306b\u4f8b\u5916\u3092\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3059\u308b\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/li>\n<\/ol>\n<\/div><\/div>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u5fdc\u7528\u30c6\u30af\u30cb\u30c3\u30af\u3092\u7406\u89e3\u3057\u3001\u9069\u5207\u306b\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u3088\u308a\u67d4\u8edf\u3067\u4fdd\u5b88\u6027\u306e\u9ad8\u3044\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br>\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001<code>find_by<\/code>\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306b\u3064\u3044\u3066\u8a73\u3057\u304f\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-26\">5. \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u8003\u616e\u3057\u305ffind_by\u306e\u4f7f\u7528\u65b9\u6cd5<\/h2>\n\n\n\n<p><code>find_by<\/code>\u30e1\u30bd\u30c3\u30c9\u306f\u7c21\u5358\u306b\u4f7f\u3048\u308b\u305f\u3081\u3001\u983b\u7e41\u306b\u5229\u7528\u3055\u308c\u307e\u3059\u304c\u3001\u5927\u898f\u6a21\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3084\u8907\u96d1\u306a\u30af\u30a8\u30ea\u3067\u306f\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306b\u6ce8\u610f\u3092\u6255\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br>\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001<code>find_by<\/code>\u3092\u52b9\u7387\u7684\u306b\u4f7f\u7528\u3059\u308b\u305f\u3081\u306e\u30c6\u30af\u30cb\u30c3\u30af\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-27\">5.1 \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u91cd\u8981\u6027<\/h3>\n\n\n\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f\u3001\u30af\u30a8\u30ea\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u5927\u5e45\u306b\u5411\u4e0a\u3055\u305b\u308b\u91cd\u8981\u306a\u8981\u7d20\u3067\u3059\u3002<br><code>find_by<\/code>\u3067\u983b\u7e41\u306b\u691c\u7d22\u3059\u308b\u5217\u306b\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u691c\u7d22\u901f\u5ea6\u3092\u5287\u7684\u306b\u6539\u5584\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001\u30e6\u30fc\u30b6\u30fc\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3067\u983b\u7e41\u306b\u691c\u7d22\u3092\u884c\u3046\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3057\u3066\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u8ffd\u52a0\u3057\u307e\u3059<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class AddIndexToUsersEmail &lt; ActiveRecord::Migration[6.1]\n  def change\n    add_index :users, :email\n  end\nend<\/pre>\n\n\n\n<p>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u8ffd\u52a0\u3059\u308b\u524d\u3068\u5f8c\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30af\u30a8\u30ea\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u6bd4\u8f03\u3057\u3066\u307f\u307e\u3057\u3087\u3046<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">User.find_by(email: 'example@example.com')<\/pre>\n\n\n\n<p><strong>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u8ffd\u52a0\u524d<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">User Load (15.2ms)  SELECT \"users\".* FROM \"users\" WHERE \"users\".\"email\" = $1 LIMIT $2  [[\"email\", \"example@example.com\"], [\"LIMIT\", 1]]<\/pre>\n\n\n\n<p><strong>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u8ffd\u52a0\u5f8c<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">User Load (0.8ms)  SELECT \"users\".* FROM \"users\" WHERE \"users\".\"email\" = $1 LIMIT $2  [[\"email\", \"example@example.com\"], [\"LIMIT\", 1]]<\/pre>\n\n\n\n<p>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u9069\u5207\u306b\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u30af\u30a8\u30ea\u306e\u5b9f\u884c\u6642\u9593\u3092\u5927\u5e45\u306b\u524a\u6e1b\u3067\u304d\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-28\">5.2 N+1\u554f\u984c\u306e\u56de\u907f<\/h3>\n\n\n\n<p>N+1\u554f\u984c\u306f\u3001\u95a2\u9023\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u3092\u500b\u5225\u306b\u53d6\u5f97\u3059\u308b\u3053\u3068\u3067\u3001\u4e0d\u5fc5\u8981\u306b\u591a\u304f\u306e\u30af\u30a8\u30ea\u304c\u767a\u751f\u3059\u308b\u554f\u984c\u3067\u3059\u3002<code>find_by<\/code>\u3092\u4f7f\u7528\u3059\u308b\u969b\u3082\u3001\u95a2\u9023\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u306f\u3053\u306e\u554f\u984c\u306b\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001\u30e6\u30fc\u30b6\u30fc\u3068\u305d\u306e\u6295\u7a3f\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">user = User.find_by(name: 'John')\nuser.posts.each do |post|\n  puts post.title\nend<\/pre>\n\n\n\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u3092\u53d6\u5f97\u3059\u308b\u30af\u30a8\u30ea\u3068\u3001\u5404\u6295\u7a3f\u3092\u53d6\u5f97\u3059\u308b\u8907\u6570\u306e\u30af\u30a8\u30ea\u3092\u767a\u884c\u3057\u307e\u3059\u3002\u3053\u308c\u3092\u56de\u907f\u3059\u308b\u306b\u306f\u3001<code>includes<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u95a2\u9023\u30c7\u30fc\u30bf\u3092\u4e8b\u524d\u306b\u8aad\u307f\u8fbc\u307f\u307e\u3059<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">user = User.includes(:posts).find_by(name: 'John')\nuser.posts.each do |post|\n  puts post.title\nend<\/pre>\n\n\n\n<p>\u3053\u306e\u65b9\u6cd5\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30e6\u30fc\u30b6\u30fc\u3068\u6295\u7a3f\u30921\u3064\u306e\u30af\u30a8\u30ea\u3067\u53d6\u5f97\u3067\u304d\u3001N+1\u554f\u984c\u3092\u56de\u907f\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-29\">5.3 \u5927\u898f\u6a21\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3067\u306e\u6700\u9069\u5316\u30c6\u30af\u30cb\u30c3\u30af<\/h3>\n\n\n\n<p>\u5927\u898f\u6a21\u306a\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u6271\u3046\u5834\u5408\u3001<code>find_by<\/code>\u306e\u4f7f\u7528\u306b\u306f\u3055\u3089\u306a\u308b\u5de5\u592b\u304c\u5fc5\u8981\u3067\u3059\u3002\u4ee5\u4e0b\u306b\u3001\u3044\u304f\u3064\u304b\u306e\u6700\u9069\u5316\u30c6\u30af\u30cb\u30c3\u30af\u3092\u7d39\u4ecb\u3057\u307e\u3059<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-30\"><strong>\u90e8\u5206\u7684\u306a\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u4f7f\u7528<\/strong><\/h4>\n\n\n\n<p>\u7279\u5b9a\u306e\u6761\u4ef6\u306b\u57fa\u3065\u3044\u3066\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u3067\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u30b5\u30a4\u30ba\u3092\u5c0f\u3055\u304f\u3057\u3001\u691c\u7d22\u3092\u9ad8\u901f\u5316\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class AddPartialIndexToUsers &lt; ActiveRecord::Migration[6.1]\n  def change\n    add_index :users, :email, where: \"status = 'active'\"\n  end\nend<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-31\"><strong>\u30af\u30a8\u30ea\u306e\u7d50\u679c\u3092\u30ad\u30e3\u30c3\u30b7\u30e5\u3059\u308b<\/strong><\/h4>\n\n\n\n<p>\u983b\u7e41\u306b\u5b9f\u884c\u3055\u308c\u308b<code>find_by<\/code>\u30af\u30a8\u30ea\u306e\u7d50\u679c\u3092\u30ad\u30e3\u30c3\u30b7\u30e5\u3059\u308b\u3053\u3068\u3067\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u30a2\u30af\u30bb\u30b9\u3092\u6e1b\u3089\u305b\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Rails.cache.fetch(\"user_#{id}\", expires_in: 12.hours) do\n  User.find_by(id: id)\nend<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-32\"><strong>\u30d0\u30c3\u30c1\u51e6\u7406\u3092\u6d3b\u7528\u3059\u308b<\/strong><\/h4>\n\n\n\n<p>\u5927\u91cf\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u51e6\u7406\u3059\u308b\u5834\u5408\u3001<code>find_each<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u30d0\u30c3\u30c1\u51e6\u7406\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">User.find_each(batch_size: 1000) do |user|\n  # \u5404\u30e6\u30fc\u30b6\u30fc\u306b\u5bfe\u3059\u308b\u51e6\u7406\nend<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-33\"><strong>\u30ab\u30a6\u30f3\u30bf\u30fc\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4f7f\u7528\u3059\u308b<\/strong><\/h4>\n\n\n\n<p>\u95a2\u9023\u30ec\u30b3\u30fc\u30c9\u306e\u6570\u3092\u983b\u7e41\u306b\u53d6\u5f97\u3059\u308b\u5834\u5408\u3001\u30ab\u30a6\u30f3\u30bf\u30fc\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4f7f\u7528\u3057\u3066\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u5411\u4e0a\u3055\u305b\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class AddPostsCountToUsers &lt; ActiveRecord::Migration[6.1]\n  def change\n    add_column :users, :posts_count, :integer, default: 0\n  end\nend\n\nclass Post &lt; ApplicationRecord\n  belongs_to :user, counter_cache: true\nend<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u6700\u9069\u5316\u30c6\u30af\u30cb\u30c3\u30af\u3092\u9069\u7528\u3059\u308b\u969b\u306f\u3001\u4ee5\u4e0b\u306e\u30c4\u30fc\u30eb\u3092\u4f7f\u7528\u3057\u3066\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u6e2c\u5b9a\u3057\u3001\u6539\u5584\u52b9\u679c\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u3092\u304a\u52e7\u3081\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-sgb-block-simple sgb-box-simple sgb-box-simple--title-normal sgb-box-simple--with-border\"><div style=\"background-color:var(--wp--preset--color--sango-main);color:#FFF\" class=\"sgb-box-simple__title\">\u304a\u3059\u3059\u3081\u306eRails\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u8a08\u6e2cgem3\u9078<\/div><div class=\"sgb-box-simple__body\" style=\"border-color:var(--wp--preset--color--sango-main);background-color:#FFF\">\n<ul class=\"wp-block-list\">\n<li><code>rack-mini-profiler<\/code> \uff1a\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u30d7\u30ed\u30d5\u30a1\u30a4\u30ea\u30f3\u30b0\u3092\u884c\u3044\u3001\u30dc\u30c8\u30eb\u30cd\u30c3\u30af\u3092\u7279\u5b9a\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>bullet<\/code> \uff1aN+1\u30af\u30a8\u30ea\u3092\u691c\u51fa\u3057\u3001\u8b66\u544a\u3092\u8868\u793a\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>benchmark-ips<\/code> \uff1aRuby\u30b3\u30fc\u30c9\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u6e2c\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<p>\u6700\u5f8c\u306b\u3001<code>find_by<\/code>\u3092\u542b\u3080ActiveRecord\u30af\u30a8\u30ea\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u6700\u9069\u5316\u3059\u308b\u305f\u3081\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3092\u307e\u3068\u3081\u307e\u3059\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5fc5\u8981\u306a\u5217\u306e\u307f\u3092\u9078\u629e\u3059\u308b\uff1a<code>select<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3001\u5fc5\u8981\u306a\u5217\u3060\u3051\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li>\u8907\u96d1\u306a\u30af\u30a8\u30ea\u306f\u30b9\u30b3\u30fc\u30d7\u306b\u30ab\u30d7\u30bb\u30eb\u5316\u3059\u308b\uff1a\u518d\u5229\u7528\u53ef\u80fd\u3067\u4fdd\u5b88\u3057\u3084\u3059\u3044\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li>\u5b9a\u671f\u7684\u306b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u5b9f\u884c\u8a08\u753b\u3092\u78ba\u8a8d\u3059\u308b\uff1a<code>EXPLAIN ANALYZE<\/code>\u3092\u4f7f\u7528\u3057\u3066\u3001\u30af\u30a8\u30ea\u306e\u5b9f\u884c\u8a08\u753b\u3092\u78ba\u8a8d\u3057\u3001\u6700\u9069\u5316\u306e\u4f59\u5730\u3092\u63a2\u308a\u307e\u3059\u3002<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">User.select(:id, :name, :email).find_by(status: 'active')<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3092\u9069\u5207\u306b\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001<code>find_by<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u52b9\u7387\u7684\u306b\u4f7f\u7528\u3057\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u5927\u5e45\u306b\u5411\u4e0a\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br>\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001<code>find_by<\/code>\u4f7f\u7528\u6642\u306e\u6ce8\u610f\u70b9\u3068\u5236\u9650\u4e8b\u9805\u306b\u3064\u3044\u3066\u8a73\u3057\u304f\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-34\">6. find_by\u306e\u6ce8\u610f\u70b9\u3068\u5236\u9650\u4e8b\u9805<\/h2>\n\n\n\n<p><code>find_by<\/code>\u30e1\u30bd\u30c3\u30c9\u306f\u4fbf\u5229\u3067\u5f37\u529b\u306a\u30c4\u30fc\u30eb\u3067\u3059\u304c\u3001\u4f7f\u7528\u3059\u308b\u969b\u306b\u306f\u3044\u304f\u3064\u304b\u306e\u6ce8\u610f\u70b9\u3068\u5236\u9650\u4e8b\u9805\u304c\u3042\u308a\u307e\u3059\u3002<br>\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001SQL\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u5bfe\u7b56\u3001\u5927\u6587\u5b57\u5c0f\u6587\u5b57\u306e\u533a\u5225\u3001\u305d\u3057\u3066\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u30dc\u30c8\u30eb\u30cd\u30c3\u30af\u306b\u3064\u3044\u3066\u8a73\u3057\u304f\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-35\">6.1 SQL\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u5bfe\u7b56<\/h3>\n\n\n\n<p>SQL\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u306f\u3001\u60aa\u610f\u306e\u3042\u308b\u30e6\u30fc\u30b6\u30fc\u304c\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u64cd\u4f5c\u3057\u305f\u308a\u3001\u6a5f\u5bc6\u60c5\u5831\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u308a\u3059\u308b\u53ef\u80fd\u6027\u306e\u3042\u308b\u6df1\u523b\u306a\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30ea\u30b9\u30af\u3067\u3059\u3002<br><code>find_by<\/code>\u3092\u4f7f\u7528\u3059\u308b\u969b\u306f\u3001\u3053\u306e\u30ea\u30b9\u30af\u306b\u7279\u306b\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u60aa\u3044\u4f8b<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">User.find_by(\"name = '#{params[:name]}'\")<\/pre>\n\n\n\n<p>\u3053\u306e\u65b9\u6cd5\u3067\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u5165\u529b\u3057\u305f\u5024\u304c\u76f4\u63a5SQL\u30af\u30a8\u30ea\u306b\u7d44\u307f\u8fbc\u307e\u308c\u308b\u305f\u3081\u3001SQL\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u653b\u6483\u306b\u5bfe\u3057\u3066\u8106\u5f31\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u4ee3\u308f\u308a\u306b\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u65b9\u6cd5\u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-36\">\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u30fc\u306e\u4f7f\u7528<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">User.find_by(\"name = ?\", params[:name])<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-37\">\u30cf\u30c3\u30b7\u30e5\u5f62\u5f0f\u306e\u4f7f\u7528<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">User.find_by(name: params[:name])<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-38\"><code>sanitize<\/code>\u30e1\u30bd\u30c3\u30c9\u306e\u4f7f\u7528<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">User.find_by(User.sanitize_sql_array([\"name = ?\", params[:name]]))<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-39\">6.2 \u5927\u6587\u5b57\u5c0f\u6587\u5b57\u306e\u533a\u5225<\/h3>\n\n\n\n<p><code>find_by<\/code>\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u5927\u6587\u5b57\u3068\u5c0f\u6587\u5b57\u3092\u533a\u5225\u3057\u307e\u3059\u3002<br>\u3053\u308c\u306f\u3001\u7279\u306b\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306a\u3069\u3092\u6271\u3046\u969b\u306b\u554f\u984c\u3068\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u30af\u30a8\u30ea\u306f\u7570\u306a\u308b\u7d50\u679c\u3092\u8fd4\u3059\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">User.find_by(email: 'user@example.com')\nUser.find_by(email: 'USER@example.com')<\/pre>\n\n\n\n<p>\u3053\u306e\u554f\u984c\u3092\u56de\u907f\u3059\u308b\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-40\">\u5c0f\u6587\u5b57\u5316\u3057\u3066\u6bd4\u8f03<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">User.find_by(\"lower(email) = ?\", email.downcase)<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-41\">\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u56fa\u6709\u306e\u95a2\u6570\u3092\u4f7f\u7528\uff08PostgreSQL\u306e\u4f8b\uff09<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">User.find_by(\"email ILIKE ?\", email)<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-42\"><code>citext<\/code>\u578b\u306e\u4f7f\u7528\uff08PostgreSQL\uff09<\/h4>\n\n\n\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30ab\u30e9\u30e0\u578b\u3092<code>citext<\/code>\u306b\u5909\u66f4\u3059\u308b\u3053\u3068\u3067\u3001\u5927\u6587\u5b57\u5c0f\u6587\u5b57\u3092\u533a\u5225\u3057\u306a\u3044\u6bd4\u8f03\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-43\">6.3 \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u30dc\u30c8\u30eb\u30cd\u30c3\u30af<\/h3>\n\n\n\n<p>\u5927\u898f\u6a21\u306a\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3084\u8907\u96d1\u306a\u6761\u4ef6\u3067\u306e\u691c\u7d22\u6642\u306b\u3001<code>find_by<\/code>\u304c\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u30dc\u30c8\u30eb\u30cd\u30c3\u30af\u3068\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6539\u5584\u306e\u305f\u3081\u306e\u30c6\u30af\u30cb\u30c3\u30af<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-44\">\u9069\u5207\u306a\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u8a2d\u5b9a<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">add_index :users, :email<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-45\">\u8907\u5408\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u4f7f\u7528<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">add_index :users, [:status, :email]<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-46\">\u90e8\u5206\u7684\u306a\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u4f7f\u7528<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">add_index :users, :email, where: \"status = 'active'\"<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-47\">\u30af\u30a8\u30ea\u306e\u30ad\u30e3\u30c3\u30b7\u30e5<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Rails.cache.fetch(\"user_#{email}\", expires_in: 1.hour) do\n  User.find_by(email: email)\nend<\/pre>\n\n\n\n<div class=\"wp-block-sgb-block-simple sgb-box-simple sgb-box-simple--title-normal sgb-box-simple--with-border\"><div style=\"background-color:var(--wp--preset--color--sango-main);color:#FFF\" class=\"sgb-box-simple__title\"><code>find_by<\/code>\u3092\u5b89\u5168\u304b\u3064\u52b9\u7387\u7684\u306b\u4f7f\u7528\u3059\u308b\u305f\u3081\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u30104STEP\u3011<\/div><div class=\"sgb-box-simple__body\" style=\"border-color:var(--wp--preset--color--sango-main);background-color:#FFF\">\n<ol class=\"wp-block-list\">\n<li>\u30e6\u30fc\u30b6\u30fc\u5165\u529b\u306f\u5e38\u306b\u30b5\u30cb\u30bf\u30a4\u30ba\u3059\u308b<\/li>\n\n\n\n<li>\u5927\u6587\u5b57\u5c0f\u6587\u5b57\u306e\u533a\u5225\u304c\u5fc5\u8981\u306a\u3044\u5834\u5408\u306f\u3001\u4e00\u8cab\u3057\u3066\u5c0f\u6587\u5b57\u5316\u3057\u3066\u6bd4\u8f03\u3059\u308b<\/li>\n\n\n\n<li>\u8907\u96d1\u306a\u6761\u4ef6\u306f\u30b9\u30b3\u30fc\u30d7\u306b\u30ab\u30d7\u30bb\u30eb\u5316\u3059\u308b<\/li>\n\n\n\n<li>\u5b9a\u671f\u7684\u306b\u30af\u30a8\u30ea\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u76e3\u8996\u3059\u308b<\/li>\n<\/ol>\n<\/div><\/div>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u6ce8\u610f\u70b9\u3068\u5236\u9650\u4e8b\u9805\u3092\u7406\u89e3\u3057\u3001\u9069\u5207\u306b\u5bfe\u51e6\u3059\u308b\u3053\u3068\u3067\u3001<code>find_by<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u5b89\u5168\u304b\u3064\u52b9\u7387\u7684\u306b\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002<br>\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u3053\u308c\u307e\u3067\u306e\u5185\u5bb9\u3092\u307e\u3068\u3081\u3001<code>find_by<\/code>\u3092\u4f7f\u3044\u3053\u306a\u3059\u305f\u3081\u306e\u91cd\u8981\u30dd\u30a4\u30f3\u30c8\u3092\u6574\u7406\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-48\">7. \u307e\u3068\u3081\uff1afind_by\u3092\u4f7f\u3044\u3053\u306a\u3059\u305f\u3081\u306e7\u3064\u306e\u91cd\u8981\u30dd\u30a4\u30f3\u30c8<\/h2>\n\n\n\n<p>\u3053\u3053\u307e\u3067\u3001Ruby on Rails\u306e<code>find_by<\/code>\u30e1\u30bd\u30c3\u30c9\u306b\u3064\u3044\u3066\u8a73\u3057\u304f\u898b\u3066\u304d\u307e\u3057\u305f\u3002<br>\u6700\u5f8c\u306b\u3001<code>find_by<\/code>\u3092\u52b9\u679c\u7684\u306b\u4f7f\u7528\u3059\u308b\u305f\u3081\u306e7\u3064\u306e\u91cd\u8981\u30dd\u30a4\u30f3\u30c8\u3092\u307e\u3068\u3081\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-sgb-block-simple sgb-box-simple sgb-box-simple--title-normal sgb-box-simple--with-border\"><div style=\"background-color:var(--wp--preset--color--sango-main);color:#FFF\" class=\"sgb-box-simple__title\"><code>find_by<\/code>\u3092\u52b9\u679c\u7684\u306b\u4f7f\u7528\u3059\u308b\u305f\u3081\u306e7\u3064\u306e\u91cd\u8981\u30dd\u30a4\u30f3\u30c8<\/div><div class=\"sgb-box-simple__body\" style=\"border-color:var(--wp--preset--color--sango-main);background-color:#FFF\">\n<ol class=\"wp-block-list\">\n<li><strong>\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3092\u7406\u89e3\u3059\u308b<\/strong>\uff1a<code>find_by<\/code>\u306e\u57fa\u672c\u7684\u306a\u69cb\u6587\u3068\u4f7f\u7528\u65b9\u6cd5\u3092\u3057\u3063\u304b\u308a\u3068\u628a\u63e1\u3057\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u304c\u5168\u3066\u306e\u57fa\u790e\u3068\u306a\u308a\u307e\u3059\u3002<\/li>\n\n\n\n<li><strong>where\u3068\u306e\u9055\u3044\u3092\u8a8d\u8b58\u3059\u308b<\/strong>\uff1a<code>find_by<\/code>\u3068<code>where<\/code>\u306e\u9055\u3044\u3092\u7406\u89e3\u3057\u3001\u9069\u5207\u306a\u5834\u9762\u3067\u4f7f\u3044\u5206\u3051\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002\u5358\u4e00\u30ec\u30b3\u30fc\u30c9\u306e\u53d6\u5f97\u306b\u306f<code>find_by<\/code>\u3001\u8907\u6570\u30ec\u30b3\u30fc\u30c9\u306e\u53d6\u5f97\u3084\u8ffd\u52a0\u306e\u7d5e\u308a\u8fbc\u307f\u304c\u5fc5\u8981\u306a\u5834\u5408\u306f<code>where<\/code>\u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\u3002<\/li>\n\n\n\n<li><strong>\u95a2\u9023\u4ed8\u3051\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u6d3b\u7528\u3059\u308b<\/strong>\uff1a\u30e2\u30c7\u30eb\u9593\u306e\u95a2\u9023\u4ed8\u3051\u3092\u5229\u7528\u3057\u3066<code>find_by<\/code>\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u3088\u308a\u8907\u96d1\u3067\u52b9\u7387\u7684\u306a\u691c\u7d22\u3092\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<\/li>\n\n\n\n<li><strong>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u610f\u8b58\u3059\u308b<\/strong>\uff1a\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u8a2d\u5b9a\u3084N+1\u554f\u984c\u306e\u56de\u907f\u306a\u3069\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u8003\u616e\u3057\u305f\u4f7f\u7528\u65b9\u6cd5\u3092\u5fc3\u304c\u3051\u307e\u3057\u3087\u3046\u3002\u5927\u898f\u6a21\u306a\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u6271\u3046\u969b\u306f\u7279\u306b\u91cd\u8981\u3067\u3059\u3002<\/li>\n\n\n\n<li><strong>\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u306b\u6ce8\u610f\u3092\u6255\u3046<\/strong>\uff1aSQL\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u5bfe\u7b56\u3092\u5fd8\u308c\u305a\u306b\u3001\u5b89\u5168\u306a\u30af\u30a8\u30ea\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002\u30e6\u30fc\u30b6\u30fc\u5165\u529b\u3092\u76f4\u63a5\u30af\u30a8\u30ea\u306b\u7d44\u307f\u8fbc\u307e\u306a\u3044\u3088\u3046\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002<\/li>\n\n\n\n<li><strong>\u5927\u6587\u5b57\u5c0f\u6587\u5b57\u306e\u533a\u5225\u306b\u6ce8\u610f\u3059\u308b<\/strong>\uff1a\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u5927\u6587\u5b57\u5c0f\u6587\u5b57\u3092\u533a\u5225\u3057\u306a\u3044\u691c\u7d22\u65b9\u6cd5\u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\u3002\u7279\u306b\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306a\u3069\u3092\u6271\u3046\u969b\u306f\u91cd\u8981\u3067\u3059\u3002<\/li>\n\n\n\n<li><strong>\u7d99\u7d9a\u7684\u306b\u5b66\u7fd2\u3068\u6700\u9069\u5316\u3092\u884c\u3046<\/strong>\uff1aRails\u306f\u5e38\u306b\u9032\u5316\u3057\u3066\u3044\u307e\u3059\u3002<code>find_by<\/code>\u306e\u65b0\u3057\u3044\u4f7f\u7528\u65b9\u6cd5\u3084\u6700\u9069\u5316\u30c6\u30af\u30cb\u30c3\u30af\u3092\u5b66\u3073\u7d9a\u3051\u308b\u3053\u3068\u304c\u3001\u3088\u308a\u3088\u3044Rails\u30a8\u30f3\u30b8\u30cb\u30a2\u306b\u306a\u308b\u305f\u3081\u306e\u9375\u3067\u3059\u3002<\/li>\n<\/ol>\n<\/div><\/div>\n\n\n\n<p><code>find_by<\/code>\u3092\u9069\u5207\u306b\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u76f4\u611f\u7684\u3067\u8aad\u307f\u3084\u3059\u3044\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u3001\u5358\u4e00\u30ec\u30b3\u30fc\u30c9\u306e\u53d6\u5f97\u306b\u6700\u9069\u5316\u3055\u308c\u305f\u52b9\u7387\u7684\u306a\u30af\u30a8\u30ea\u3092\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<br>\u307e\u305f\u3001<code>nil<\/code>\u306e\u6271\u3044\u304c\u7c21\u5358\u3067\u3001\u6761\u4ef6\u6307\u5b9a\u3082\u67d4\u8edf\u306b\u884c\u3048\u308b\u3068\u3044\u3046\u5229\u70b9\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u6b21\u306e\u30b9\u30c6\u30c3\u30d7\u3068\u3057\u3066\u3001\u3088\u308a\u9ad8\u5ea6\u306aActiveRecord\u306e\u30af\u30a8\u30ea\u30e1\u30bd\u30c3\u30c9\u3092\u5b66\u3093\u3060\u308a\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u306b\u3064\u3044\u3066\u6df1\u304f\u7406\u89e3\u3057\u305f\u308a\u3001Rails\u306e\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3092\u5b66\u3093\u3060\u308a\u3059\u308b\u3053\u3068\u3092\u304a\u3059\u3059\u3081\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p><code>find_by<\/code>\u306f\u975e\u5e38\u306b\u4fbf\u5229\u306a\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u304c\u3001\u3053\u308c\u306fRails\u304c\u63d0\u4f9b\u3059\u308b\u5f37\u529b\u306a\u30c4\u30fc\u30eb\u306e\u4e00\u3064\u306b\u904e\u304e\u307e\u305b\u3093\u3002\u7d99\u7d9a\u7684\u306a\u5b66\u7fd2\u3068\u5b9f\u8df5\u3092\u901a\u3058\u3066\u3001Rails\u306e\u771f\u306e\u529b\u3092\u5f15\u304d\u51fa\u3057\u3001\u52b9\u7387\u7684\u3067\u4fdd\u5b88\u6027\u306e\u9ad8\u3044\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u958b\u767a\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u3053\u3068\u3092\u9858\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ruby on Rails\u306efind_by\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u52b9\u7387\u7684\u306b\u30ec\u30b3\u30fc\u30c9\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306e\u5f37\u529b\u306a\u30c4\u30fc\u30eb\u3067\u3059\u3002\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001find_by\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u304b\u3089\u9ad8\u5ea6\u306a\u30c6\u30af\u30cb\u30c3\u30af\u3001\u305d\u3057\u3066\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3068\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":3166,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,44],"tags":[],"class_list":{"0":"post-20","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-ruby","8":"category-ruby-rails"},"_links":{"self":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=20"}],"version-history":[{"count":15,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":101,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions\/101"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/media\/3166"}],"wp:attachment":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}