<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>opiyotan</author_name>
  <author_url>https://blog.hatena.ne.jp/opiyotan/</author_url>
  <blog_title>おぴよの気まぐれ日記</blog_title>
  <blog_url>https://opiyotan.hatenablog.com/</blog_url>
  <categories>
    <anon>Ruby</anon>
    <anon>Rails</anon>
    <anon>Tips</anon>
  </categories>
  <description>Ruby on Railsでデータベースにデータが存在するかどうかチェックしたい場合があると思います。 そもそもデータがあるかどうか知りたい時 ログインしたユーザーが管理者ユーザーがどうかをチェックしたい そんな時はModel.exists?()を使いましょうって話です。 データが存在するかチェックする 条件付きで存在をチェックする find_byも同じ使い方出来るじゃね？ 参考サイト データが存在するかチェックする &gt; User.exists? User Exists (3.0ms) SELECT 1 AS one FROM &quot;users&quot; LIMIT $1 [[&quot;LIMIT&quot;, 1]] =…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fopiyotan.hatenablog.com%2Fentry%2Ftips-model-exists&quot; title=&quot;【Rails】データが1件でもあるかどうかチェックするには`Model.exists?` - おぴよの気まぐれ日記&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>https://cdn.user.blog.st-hatena.com/default_entry_og_image/110785513/1514221383750427</image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2019-06-18 22:48:26</published>
  <title>【Rails】データが1件でもあるかどうかチェックするには`Model.exists?`</title>
  <type>rich</type>
  <url>https://opiyotan.hatenablog.com/entry/tips-model-exists</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
