On Nov 8, 10:41 am, "[email protected]"
<[email protected]> wrote:
> what i need:
> if :record is in the database -> upgrade his counter
> else create :record (with his counter on 1)
>
> this should be done with an atomic operation, to avoid race
> conditions.
> What is the best way to do this with activerecord?
> I read about transactions, but as i understand a transaction acts on a
> single connection to the database.
incrementing the counter is simple enough - AR's increment_counter
method basically does update foos set counter = counter + 1 where ...
To avoid duplicate records being created I'd create a unique index on
whatever it is that identifies a record
Fred
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---