-
Notifications
You must be signed in to change notification settings - Fork 21.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate using
id
for custom primary keys
During our work on composite keys in Rails it became clear that we were conflating the meaning of `id`. In most cases applications use the `id` column as the primary key. However Rails allows you to set a custom primary key and use `id` to call that. For example if `Post` has a primary key named `title` calling `Post.first.id` will return the title, even if there is an `id` column on the posts table. Essenstially the problem is that by treating `id` as special there is no good API for accessing or setting an `id` attribute on a record with a custom primary key. This PR proposes removing the special meaning for `id`. If an application is using a standard `id` column as the primary key, no changes will be required. If an application does have a custom primary key Rails will fire a deprecation warning and point them to use the `primary_key_*` methods instead. This will also be useful for composite primary keys becasue it's likely many applications will use keys like `[:shop_id, :id]`. Without this change the only way to access the actual id attribute would be `post.attributes["id"]` or `post._read_attribute("id")`. With this change applications can access the full key with `post.primary_key_value` or just the `id` attribute with `post.id`.
- Loading branch information
1 parent
bd8aeea
commit c15dca4
Showing
45 changed files
with
307 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.