0

I'm doign a voting application and I need to update votes count for this I want to use update SQL, because in other cases voices may be lost (AR generates update statement with value, but what if previous request already incremented column value?).

Ho do I do that?

2 Answers 2

2

You can use increment_counter which does a direct update in the database without caring about the actual value of your Active Record contents:

Vote.increment_counter :vote_value, 5
Sign up to request clarification or add additional context in comments.

Comments

0

Try something like:

Movie.update_counters id, :like_count => 1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.