I understand what you mena. However, how would one handle such an increment on concurrent threads/processes? You do have to handle the ambiguity somehow. Delegate the responsibility to the DB sounds reasonable, but some more inputs would be nice.
Segunda-feira, 21 de Janeiro de 2013 0:56:37 UTC+1, ajsharp escreveu: > > The method is here: > https://github.com/rails/rails/blob/master/activerecord/lib/active_record/persistence.rb#L288 > . > > The method takes the in-memory attribute value and increments it by the > specified amount. A safer approach (from an isolation standpoint) would be > to let the database determine the value. Instead of telling the database > what value to persist in the database, the SQL can written (at least for > postgres) so that the database will atomically increment a value: > > UPDATE "posts" SET view_count = view_count + 1 WHERE id=123; > > Currently, rails generates the following SQL: > > UPDATE "posts" SET "view_count" = 3, "updated_at" = '2013-01-20 > 23:20:24.154852' WHERE "posts"."id" = 123 > > It would be great to see a method like this to perform atomic update > operations for databases that support it. If there's support for this, I'm > happy to write the patch. Thanks! > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/t14Sw5WWZJQJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.