开发者

Creating unique association with Rails

开发者 https://www.devze.com 2023-03-19 01:37 出处:网络
How to create an unique association (many to many) with Rails ? Ive : article +----开发者_Go百科-+ article_user +------+ user

How to create an unique association (many to many) with Rails ?

Ive : article +----开发者_Go百科-+ article_user +------+ user

I want that the user can mark only one time an article, not twice or more.

How can I do that ? I Tried with uniqueness it doesn't work.


Sounds like you're looking for a composite primary key - so that a combination of article and user is always unique in your joining table.

Last time I check this isn't natively possible in ActiveRecord - you might want to try something like this:

http://compositekeys.rubyforge.org/

Stu

0

精彩评论

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