Skip to content

Commit e7483ba

Browse files
authored
Merge pull request rails#46228 from jasonfb/main
adds documentation for flag --primary-key-type=uuid passed to Rails model generator
2 parents caf9413 + b56a79e commit e7483ba

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

guides/source/active_record_postgresql.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,25 @@ irb> device.id
501501
=> "814865cd-5a1d-4771-9306-4268f188fe9e"
502502
```
503503

504-
NOTE: `gen_random_uuid()` (from `pgcrypto`) is assumed if no `:default` option was
505-
passed to `create_table`.
504+
NOTE: `gen_random_uuid()` (from `pgcrypto`) is assumed if no `:default` option
505+
was passed to `create_table`.
506+
507+
To use the Rails model generator for a table using UUID as the primary key, pass
508+
`--primary-key-type=uuid` to the model generator.
509+
510+
For example:
511+
512+
```ruby
513+
rails generate model Device --primary-key-type=uuid kind:string
514+
```
515+
516+
When building a model with a foreign key that will reference this UUID, treat
517+
`uuid` as the native field type, for example:
518+
519+
```ruby
520+
rails generate model Case device_id:uuid
521+
```
522+
506523

507524
Generated Columns
508525
-----------------

0 commit comments

Comments
 (0)