<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>goldenCat1990</author_name>
  <author_url>https://blog.hatena.ne.jp/goldenCat1990/</author_url>
  <blog_title>jun01tの日記</blog_title>
  <blog_url>https://blog.jun01t.com/</blog_url>
  <categories>
    <anon>技術</anon>
  </categories>
  <description>Railsのoptional: trueとは？使い方と注意点を解説！ Railsのbelongs_toには、optional: trueというオプションがあります。このオプションを使うと、belongs_toで関連付けられたモデルが必須でない状態に設定できます。この記事では、optional: trueの使い方や注意点について解説します。 optional: trueの基本 Rails 5以降、belongs_toの関連はデフォルトで必須になっています。そのため、関連先が存在しない場合、バリデーションエラーになります。 デフォルトの動作 class Book &lt; ApplicationReco…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fblog.jun01t.com%2Fentry%2F2024%2F12%2F07%2F115405&quot; title=&quot;Railsの`optional: true`とは？使い方と注意点を解説！ - jun01tの日記&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>2024-12-07 11:54:05</published>
  <title>Railsの`optional: true`とは？使い方と注意点を解説！</title>
  <type>rich</type>
  <url>https://blog.jun01t.com/entry/2024/12/07/115405</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
