Create a gist now

Instantly share code, notes, and snippets.

Using model's sequence next value before inserting for special manipulation.
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment