<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>karlley_jp</author_name>
  <author_url>https://blog.hatena.ne.jp/karlley_jp/</author_url>
  <blog_title>時々とおまわり</blog_title>
  <blog_url>https://karlley.hatenablog.jp/</blog_url>
  <categories>
    <anon>Rails</anon>
  </categories>
  <description>コードレビューでpresense: true の使い方を指摘されたので調べてみました。 結論 関連付けたモデルの外部キーへのpresense: true は必要ない。 アソシエーションによって紐付けられた外部キーの存在しない値やnil の場合へのpresenceバリデーションは自動的に付与される(Rails5から)ので不要になる。 Rails5からbelongs_toアソシエーションの挙動が変わった - SHOYAN BLOG # 親モデル class User &lt; ApplicationRecord has_many :books end # 子モデル class Book &lt; Applic…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fkarlley.hatenablog.jp%2Fentry%2F2023%2F01%2F07%2F081205&quot; title=&quot;【Rails】関連付けたモデルの外部キーへのpresense: trueは必要ない - 時々とおまわり&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>2023-01-07 08:12:05</published>
  <title>【Rails】関連付けたモデルの外部キーへのpresense: trueは必要ない</title>
  <type>rich</type>
  <url>https://karlley.hatenablog.jp/entry/2023/01/07/081205</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
