Mention composite primary keys for migrations and querying

This commit is contained in:
Noah Gibbs 2023-09-05 12:34:40 +01:00
parent 4f2fa59734
commit 586c79d8b0
No known key found for this signature in database
GPG Key ID: 428AADFC4718A6AE
2 changed files with 5 additions and 2 deletions

@ -370,8 +370,9 @@ end
This method creates a `products` table with a column called `name`.
By default, `create_table` will implicitly create a primary key called `id` for
you. You can change the name of the column with the `:primary_key` option or,
if you don't want a primary key at all, you can pass the option `id: false`.
you. You can change the name of the column with the `:primary_key` option, or
pass an array to `:primary_key` for a composite primary key. If you don't want
a primary key at all, you can pass the option `id: false`.
If you need to pass database specific options you can place an SQL fragment in
the `:options` option. For example:

@ -199,6 +199,8 @@ SELECT * FROM customers WHERE (customers.id IN (1,10))
WARNING: The `find` method will raise an `ActiveRecord::RecordNotFound` exception unless a matching record is found for **all** of the supplied primary keys.
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.
#### `take`
The [`take`][] method retrieves a record without any implicit ordering. For example: