Created
April 10, 2011 04:22
-
-
Save derencius/912042 to your computer and use it in GitHub Desktop.
Using model's sequence next value before inserting for special manipulation.
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
# 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