1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Improve documentation [ci skip]

Add information about usage `uuid` type with `reference`
This commit is contained in:
Jacek Nakonieczny 2015-04-18 06:44:00 +02:00
parent 8cf73b9adb
commit db8b06099f

View file

@ -245,6 +245,7 @@ article.save!
* [type definition](http://www.postgresql.org/docs/9.3/static/datatype-uuid.html) * [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) * [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 ```ruby
# db/migrate/20131220144913_create_revisions.rb # db/migrate/20131220144913_create_revisions.rb
@ -263,6 +264,30 @@ revision = Revision.first
revision.identifier # => "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11" 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 ### Bit String Types
* [type definition](http://www.postgresql.org/docs/9.3/static/datatype-bit.html) * [type definition](http://www.postgresql.org/docs/9.3/static/datatype-bit.html)