开发者

Validating uniqueness of a record in a join table

I have a join table with this setup:

create_table "showable_videos", :force => true do |t|
  t.integer  "user_id"
  t.integer  "profile_id"
  t.integer  "video_id"
  t.datetime "created_at"
  t.datetime "updated_at"
end

How do开发者_如何转开发 I validate the uniqueness of a showable_video? In other words, I need to make sure no two showable_videos have all the same user_id, profile_id, and video_id.


Try having a model ShowableVideo and put there:

validates_uniqueness_of :user_id, :scope => [:profile_id, :video_id]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜