0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ポリモーフィックリレーションでリレーション先のモデルが存在しないものは取得対象外にしたい

0
Last updated at Posted at 2023-07-26

この記事は個人ブログに移行しました。最新情報はブログ版をご覧ください。

要点

  • 関連モデルが削除されているデータは取得対象外にしたい。 そんなときあるよねー!
  • 余談(commentable typeに登録する値) — ポリモーフィックタイプはデフォルトでモデル名が登録されるが、 将来的にモデル名(ディレクトリ)が変更されたり CQRSで同じモデルを複数クラス定義する可能性もあるので 文字列定義してそれを使用するのがオススメ。 (App\Models\Post ではなく post で登録し...
  • ポリモーフィックリレーションでリレーション先のモデルが存在しないものは取得対象外にしたいの実装手順やハマりどころはブログ本文で詳しく紹介しています。

もっと詳しく

  • ブログではコード全文や補足資料を継続的に更新しています
  • 気になる点があればコメントください🙌
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?