<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>ayacai115</author_name>
  <author_url>https://blog.hatena.ne.jp/ayacai115/</author_url>
  <blog_title>スコーンの開発日記</blog_title>
  <blog_url>https://ayacai115.hateblo.jp/</blog_url>
  <categories>
    <anon>Ruby on Rails</anon>
  </categories>
  <description>find_byしてしまうと… ActiveRecordのscopeでは、クエリの実行結果がnilだとallを返してしまう。 class Order &lt; ActiveRecord::Base scope :bar, -&gt; { find_by(foo: 'bar') } end Order.find_by(foo: 'bar')と同じ動きだと思ってnilを期待すると、allが返る。 # レコードがあるとき Order.bar =&gt; #&lt;Order ...&gt; # ActiveRecord::Relationではなく、インスタンスが返る # レコードがないとき Order.bar =&gt; [#&lt;Orde…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fayacai115.hateblo.jp%2Fentry%2F2019%2F10%2F01%2F191558&quot; title=&quot;ActiveRecordのscopeではfind_byしない方がよい - スコーンの開発日記&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2019-10-01 19:15:58</published>
  <title>ActiveRecordのscopeではfind_byしない方がよい</title>
  <type>rich</type>
  <url>https://ayacai115.hateblo.jp/entry/2019/10/01/191558</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
