現状、下記のようなBlog、Topic、User、Commentの4モデルある状態です。
BlogとTopicにコメント機能を実装しようと考えています。
「user_idとblog_id」と、「user_idとtopic_id」の組み合わせで一意制約を設けた状態でコメント機能を作りたいのですが、モデル側のバリデーションがわからずご教示のほどよろしくお願いします。
下記、現状です。
scaffold
1rails g scaffold Blog title:string body:text user:references 2rails g scaffold Topic title:string body:text user:references 3rails g model User name:string 4rails g model Comment body:text user:references blog:references topic:references
BlogModel
1has_many :comments
TopicModel
1has_many :comments
CommentModel
1belongs_to :blog 2belongs_to :topic
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。