-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
49 lines (40 loc) · 1.35 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
UUIDPrimaryKey
==============
Copyright 2006-2007, Chris Hapgood
MIT License
Derived from the works of several others, including Demetrio Nunes, Paul Dix and Lee Jensen.
Requirements: UUIDTools GEM (gem install uuidtools)
In any model class requiring a UUID PK, invoke UUIDPrimaryKey, optionally with
the name of the PK column in your database. Example:
class Person < ActiveRecord::Base
UUIDPrimaryKey
end
class Place < ActiveRecord::Base
UUIDPrimaryKey :column => 'uuid'
end
Hints:
1. To override the value of the PK from the application, define an
initialize method in your model like this:
class Person < ActiveRecord::Base
UUIDPrimaryKey :column => 'uuid'
def initialize(params = nil)
super
self.id = params[:uuid] unless params[:uuid].nil?
end
end
2. To define a reasonable colum using migrations, try this:
class AddPeople < ActiveRecord::Migration
def self.up
create_table :people, :id => false do |t|
t.column :uuid, :string, :limit => 36
t.column :firstnames, :string, :limit => 55
t.column :lastname, :string, :limit => 35
t.column :created_at, :timestamp
t.column :updated_at, :timestamp
end
execute("ALTER TABLE people ADD PRIMARY KEY(uuid)")
end
def self.down
drop_table :people
end
end