Skip to content

Instantly share code, notes, and snippets.

@emilpetkov
Created March 28, 2017 21:55
Show Gist options
  • Save emilpetkov/3d468f41181cc11040bd9b806ca1d704 to your computer and use it in GitHub Desktop.
Save emilpetkov/3d468f41181cc11040bd9b806ca1d704 to your computer and use it in GitHub Desktop.
class TransactionIdSequence < ActiveRecord::Base
belongs_to :contract
def next_transaction_id
TransactionIdSequence.transaction do
TransactionIdSequence.connection.execute("UPDATE `#{self.class.table_name}` SET `transaction_id_sequence` = `transaction_id_sequence` + 1 WHERE `id` = #{id}")
TransactionIdSequence.connection.select_value("SELECT `transaction_id_sequence` FROM `#{self.class.table_name}` WHERE `id` = #{id}").to_i
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment