Created
August 13, 2017 12:34
-
-
Save nitschmann/f6e0a0d814dec5c4da37d9a75ac8ed06 to your computer and use it in GitHub Desktop.
uuid as primary key
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
module UuidAsPrimaryKey | |
extend ActiveSupport::Concern | |
included do | |
before_create :assign_uuid | |
end | |
protected | |
def assign_uuid | |
return if self.id.present? | |
self.id = SecureRandom.uuid | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment