Skip to content

Commit 6633671

Browse files
Merge pull request rails#49150 from Shopify/rails_guides_updates_for_composite_primary_keys
Rails Guides: describe composite primary keys (CPK) for migrations and querying
2 parents 5fc58c8 + 586c79d commit 6633671

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

guides/source/active_record_migrations.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,9 @@ end
370370
This method creates a `products` table with a column called `name`.
371371

372372
By default, `create_table` will implicitly create a primary key called `id` for
373-
you. You can change the name of the column with the `:primary_key` option or,
374-
if you don't want a primary key at all, you can pass the option `id: false`.
373+
you. You can change the name of the column with the `:primary_key` option, or
374+
pass an array to `:primary_key` for a composite primary key. If you don't want
375+
a primary key at all, you can pass the option `id: false`.
375376

376377
If you need to pass database specific options you can place an SQL fragment in
377378
the `:options` option. For example:

guides/source/active_record_querying.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ SELECT * FROM customers WHERE (customers.id IN (1,10))
199199

200200
WARNING: The `find` method will raise an `ActiveRecord::RecordNotFound` exception unless a matching record is found for **all** of the supplied primary keys.
201201

202+
If your table uses a composite primary key, you'll need to pass an array to find a single item. You can also pass an array of arrays to find multiple records.
203+
202204
#### `take`
203205

204206
The [`take`][] method retrieves a record without any implicit ordering. For example:

0 commit comments

Comments
 (0)