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

Copy edits for primary_key documentation in association guide. [ci skip]

This commit is contained in:
Zachary Scott 2015-04-10 17:27:40 -07:00
parent 47dc07313b
commit d2998764c5

View file

@ -916,9 +916,10 @@ TIP: In any case, Rails will not create foreign key columns for you. You need to
##### `:primary_key`
By convention, Rails assumes that the column used to hold the primary key of it's table is `id`, and `:primary_key` allows you to specify a different column.
By convention, Rails assumes that the `id` column is used to hold the primary key of it's table.
The `:primary_key` option allows you to specify a different column.
Let's say that `users` table has `guid` as the primary key. And the requirement is that `todos` table should hold `guid` column value in the foreign key `user_id`. This can be achieved like this
For example, given we have a `users` table with `guid` as the primary key. If we want a separate `todos` table to hold the foreign key `user_id` in the `guid` column, then we can use `primary_key` to achieve this like so:
```ruby
class User < ActiveRecord::Base
@ -930,7 +931,7 @@ class Todo < ActiveRecord::Base
end
```
Now if we execute `@user.todos.create` then `@todo` record will have `user_id` value as the `guid` value of `@user`.
When we execute `@user.todos.create` then the `@todo` record will have `user_id` value as the `guid` value of `@user`.
##### `:inverse_of`