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

Fix to_param id generation for partial composite keys #49080

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

gmcgibbon
Copy link
Member

Motivation / Background

This Pull Request has been created because parameter generation for CPK models is subtly broken.

Detail

This Pull Request changes Action View and Active Model by adding tests for url_for when using composite primary key models and fixes to_param output for CPK models with partially complete IDs (eg. one column has a value but the other doesn't).

Additional information

Somewhat similar to #49069, which made me think that to_key might actually be the source of both bugs. However, after reviewing the documentation, it seems like the current behaviour is correct:

# Returns an Array of all key attributes if any of the attributes is set, whether or not
# the object is persisted. Returns +nil+ if there are no key attributes.

Note any attribute being set, so partial CPK IDs are expected. I assume we don't want parameters with incomplete CPK IDs, so I fixed it in to_param instead.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

Adds tests for url_for use with composite primary key models. Fixes bug
related to new CPK model to_param generation.
@eileencodes eileencodes merged commit 621bc68 into rails:main Aug 29, 2023
3 checks passed
@gmcgibbon gmcgibbon deleted the generate_correct_cpk_param branch August 29, 2023 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants