开发者

Validating uniqueness of a record in a join table

开发者 https://www.devze.com 2023-03-06 15:14 出处:网络
I have a join table with this setup: create_table \"showable_videos\", :force => true do |t| t.integer\"user_id\"

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

精彩评论

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