aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-12-01 03:40:27 +0900
committerGitHub <noreply@github.com>2018-12-01 03:40:27 +0900
commit604fac6d7191fca102380b1a5f5eb9c619fb407f (patch)
tree49df8f5b1b94503f54938a7eb7a47ed8b23586d9
parent25c076117ce9bb3efcf686c110187206e428b96a (diff)
parent220494185c84cf62d60ddcb1fa3527da9d758578 (diff)
downloadrails-604fac6d7191fca102380b1a5f5eb9c619fb407f.tar.gz
rails-604fac6d7191fca102380b1a5f5eb9c619fb407f.tar.bz2
rails-604fac6d7191fca102380b1a5f5eb9c619fb407f.zip
Merge pull request #34577 from gmcgibbon/id_as_non_pk_docs
Clarify no support for non PK id columns [ci skip]
-rw-r--r--activerecord/lib/active_record/attribute_methods/primary_key.rb11
-rw-r--r--guides/source/active_record_basics.md2
2 files changed, 8 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/primary_key.rb b/activerecord/lib/active_record/attribute_methods/primary_key.rb
index 9b267bb7c0..6af5346fa7 100644
--- a/activerecord/lib/active_record/attribute_methods/primary_key.rb
+++ b/activerecord/lib/active_record/attribute_methods/primary_key.rb
@@ -14,38 +14,39 @@ module ActiveRecord
[key] if key
end
- # Returns the primary key value.
+ # Returns the primary key column's value.
def id
sync_with_transaction_state
primary_key = self.class.primary_key
_read_attribute(primary_key) if primary_key
end
- # Sets the primary key value.
+ # Sets the primary key column's value.
def id=(value)
sync_with_transaction_state
primary_key = self.class.primary_key
_write_attribute(primary_key, value) if primary_key
end
- # Queries the primary key value.
+ # Queries the primary key column's value.
def id?
sync_with_transaction_state
query_attribute(self.class.primary_key)
end
- # Returns the primary key value before type cast.
+ # Returns the primary key column's value before type cast.
def id_before_type_cast
sync_with_transaction_state
read_attribute_before_type_cast(self.class.primary_key)
end
- # Returns the primary key previous value.
+ # Returns the primary key column's previous value.
def id_was
sync_with_transaction_state
attribute_was(self.class.primary_key)
end
+ # Returns the primary key column's value from the database.
def id_in_database
sync_with_transaction_state
attribute_in_database(self.class.primary_key)
diff --git a/guides/source/active_record_basics.md b/guides/source/active_record_basics.md
index b9e24099b1..a67e2924d7 100644
--- a/guides/source/active_record_basics.md
+++ b/guides/source/active_record_basics.md
@@ -202,6 +202,8 @@ class Product < ApplicationRecord
end
```
+NOTE: Active Record does not support using non-primary key columns named `id`.
+
CRUD: Reading and Writing Data
------------------------------