1 # This plugin for ActiveRecord makes the "ID" field into a URL-safe GUID
2 # It is a mashup by Andy Singleton <andy@assembla.com> that includes
3 # * the UUID class from Bob Aman.
4 # * the plugin skeleton from Demetrius Nunes
5 # * the 22 character URL-safe format from Andy Singleton
6 # You can get standard 36 char UUID formats instead
7 # TODO: Auto-detect a character ID field and use a GUID in this case (DRY principle)
9 # This library is free software; you can redistribute it and/or modify it
10 # under the terms of the MIT license.
13 # Install as a plugin in the rails directory vendor/plugin/guid
14 # define ID as char(22)
15 # call "usesguid" in ActiveRecord class declaration, like
16 class Mymodel < ActiveRecord::Base
19 # if your ID field is not called "ID", call "usesguid :column =>'IdColumnName' "
21 # if you create your tables with migrations, you need to bypass the rails default primary key index. Do this:
23 create_table :mytable, :id => false do |t|
24 t.column :id, :string, :limit => 22
28 execute "ALTER TABLE mytable ADD PRIMARY KEY (id)"