aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2015-04-18 12:52:27 +0200
committerYves Senn <yves.senn@gmail.com>2015-04-18 12:54:07 +0200
commit154e13c00b497d22e294cddb1a1657ffe38eea1c (patch)
tree026d53d9b2e26f050360c77bf2c197a463e3aa8f /guides
parent8cf73b9adb772f3ba9a8d5a4cc507c2c077e04a4 (diff)
parentdb8b06099f1f7a0e2f109c3574bbd88c99d43bce (diff)
downloadrails-154e13c00b497d22e294cddb1a1657ffe38eea1c.tar.gz
rails-154e13c00b497d22e294cddb1a1657ffe38eea1c.tar.bz2
rails-154e13c00b497d22e294cddb1a1657ffe38eea1c.zip
Merge pull request #19806 from vircung/master
Improve documentation for uuid [ci skip]
Diffstat (limited to 'guides')
-rw-r--r--guides/source/active_record_postgresql.md23
1 files changed, 23 insertions, 0 deletions
diff --git a/guides/source/active_record_postgresql.md b/guides/source/active_record_postgresql.md
index 4d9c1776f4..66a11e5785 100644
--- a/guides/source/active_record_postgresql.md
+++ b/guides/source/active_record_postgresql.md
@@ -245,6 +245,7 @@ article.save!
* [type definition](http://www.postgresql.org/docs/9.3/static/datatype-uuid.html)
* [generator functions](http://www.postgresql.org/docs/9.3/static/uuid-ossp.html)
+NOTE: you need to enable the `uuid-ossp` extension to use uuid.
```ruby
# db/migrate/20131220144913_create_revisions.rb
@@ -263,6 +264,28 @@ revision = Revision.first
revision.identifier # => "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11"
```
+You can use `uuid` type to define references in migrations
+
+```ruby
+# db/migrate/20150418012400_create_blog.rb
+create_table :posts, id: :uuid
+
+create_table :comments, id: :uuid do |t|
+ # t.belongs_to :post, type: :uuid
+ t.references :post, type: :uuid
+end
+
+# app/models/post.rb
+class Post < ActiveRecord::Base
+ has_many :comments
+end
+
+# app/models/comment.rb
+class Comment < ActiveRecord::Base
+ belongs_to :post
+end
+```
+
### Bit String Types
* [type definition](http://www.postgresql.org/docs/9.3/static/datatype-bit.html)