开发者

Creating unique association with Rails

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜