I have this kind of db:schema :
articles +——-+ article_users +——+ user
How can I restrict an user to vote more than one time on an article ?
Is there a validation rule to put on model for that ?
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.
Begin by replacing to a has_many :through relationship if you’re using has_and_belongs_to_many, so that you’ll be able to access the relation model, ie. : ArticleUser.
Then first validate the relation model ArticleUser :
If you want to know if a user has already voted for an article, you can use something like :
or directly using the has_many relation…