开发者

Rails HABTM validation

开发者 https://www.devze.com 2023-02-19 01:58 出处:网络
Validation for HABTM is not working, I used the following code: Class GroupsUsers < ActiveRecord::Base

Validation for HABTM is not working, I used the following code:

Class GroupsUsers < ActiveRecord::Base

  belongs_to :user
  belongs_to :group
  validates_uniqueness_of :user_id, :scope => :group_id

end 

Does anyone have a solution as to why this is not w开发者_如何学Corking?


I think that it's probably the plural model name. Try using GroupUser instead.

EDIT

As noted in a comment above(i didn't notice at first), you say that you do a HABTM. You actually don't do that. It's more like the intermediate model of a has_many through association.

0

精彩评论

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