###前提・実現したいこと
Railsで日記投稿アプリケーションを作成するために、
model設計をしています。
中間テーブルを使用する予定ですが、
親テーブルが消えたらそれに関連する中間テーブルのレコードも削除したいです。
【】内の記述方法で良いのかわかりません。
diary,commentは普通にhas_manyにdependent : destroy
を使用すれば良いことはわかっているのですが、
中間テーブルでthroughを使用している場合に
dependent : destroyが使用できるかと記載方法を教えていただきたいです。
###発生している問題・エラーメッセージ
model設計
・ユーザ情報テーブル:user
ユーザID:user_id
ユーザネーム: name
パスワード:password
メールアドレス:email
has_many: diary, dependent : destroy has_many: tag_mst, through: : user_tag
・日記テーブル:diary
日記ID:diary_id
タイトル:title
本文:body
ユーザID:user_id
belongs_to :user has_many: diary_tag_mst has_many: comment, dependent : destroy 【has_many: tag_mst, through: : diary_tag_mst, dependent : destroy】
・コメントテーブル:comment
コメントID:comment_id
コメント:comment
日記ID:diary_id
belongs_to :user belongs_to :diary
・タグマスタテーブル:tag_mst
タグID:tag_id
タグ名称:tag_name
日記ID:diary_id
has_many: diary_tag_mst has_many: diary, through: : diary_tag_mst has_many: user, through: : user_tag
・中間テーブル(日記とタグマスタ):diary_tag_mst
日記ID:diary_id
タグID:tag_id
belongs_to :diary_id belongs_to :tag_id
・中間テーブル(userとtag_mst):use_tag
ユーザID:user_id
タグID:tag_id
カウント(diary_tag_mst更新ごとに自動更新):count
belongs_to : user belongs_to : tag_mst
あなたの回答
tips
プレビュー