How to create an unique association (many to many) with Rails ?
Ive :
article +—–+ 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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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