Created
March 28, 2017 21:55
-
-
Save emilpetkov/3d468f41181cc11040bd9b806ca1d704 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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