开发者

Ruby on Rails 3: increment value using sql

I'm doign a voti开发者_运维技巧ng 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?


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


Try something like:

Movie.update_counters id, :like_count => 1
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜