public
Last active

Using model's sequence next value before inserting for special manipulation.

  • Download Gist
client.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# id : serial
# check_digit : integer
 
class Client
 
set_primary_key :id
before_create :define_check_digit
 
private
 
def self.next_id
Integer(connection.select_value "SELECT nextval('#{sequence_name}')")
end
 
def define_check_digit
self.id = self.class.next_id
self.check_digit = Digit.calc id
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.