Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails Guides: describe composite primary keys (CPK) for migrations and querying #49150

Conversation

noahgibbs
Copy link
Contributor

In the active_record_migrations guide, mention that a composite primary key can be specified using an array.

In the active_record_querying guide, mention that find takes an array or array of arrays for composite primary keys.

Both of these are recent API changes, not yet mentioned in the Rails guides.

@rails-bot rails-bot bot added the docs label Sep 5, 2023
@adrianna-chang-shopify adrianna-chang-shopify merged commit 6633671 into rails:main Sep 5, 2023
4 checks passed
@adrianna-chang-shopify adrianna-chang-shopify deleted the rails_guides_updates_for_composite_primary_keys branch September 5, 2023 13:06
@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should include an example. Can you open a new PR that shows the find and sql generated like the above examples?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great idea. Will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants