aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/active_record_postgresql.md
diff options
context:
space:
mode:
authorJacek Nakonieczny <jacek.nakonieczny@gmail.com>2015-04-18 06:44:00 +0200
committerJacek Nakonieczny <jacek.nakonieczny@gmail.com>2015-04-18 06:57:34 +0200
commitdb8b06099f1f7a0e2f109c3574bbd88c99d43bce (patch)
tree8f8bb4c1c6e3fc2100c1beaee715e75b83c5f92f /guides/source/active_record_postgresql.md
parent8cf73b9adb772f3ba9a8d5a4cc507c2c077e04a4 (diff)
downloadrails-db8b06099f1f7a0e2f109c3574bbd88c99d43bce.tar.gz
rails-db8b06099f1f7a0e2f109c3574bbd88c99d43bce.tar.bz2
rails-db8b06099f1f7a0e2f109c3574bbd88c99d43bce.zip
Improve documentation [ci skip]
Add information about usage `uuid` type with `reference`
Diffstat (limited to 'guides/source/active_record_postgresql.md')
-rw-r--r--guides/source/active_record_postgresql.md25
1 files changed, 25 insertions, 0 deletions
diff --git a/guides/source/active_record_postgresql.md b/guides/source/active_record_postgresql.md
index 4d9c1776f4..395eda1644 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,30 @@ 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
+def change
+ create_table :posts, id: :uuid
+end
+
+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)