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

Ensure that decode returns all parts of composite key #71

Merged
merged 2 commits into from
Aug 1, 2024

Conversation

plabaj
Copy link
Contributor

@plabaj plabaj commented Aug 1, 2024

This pull request addresses a bug in the decoding of composite keys. In the current implementation, when a model is defined with a composite primary key, the decoding process incorrectly strips out the first key component. This fix ensures that all components of the composite key are retained and correctly decoded.

For models with composite keys, such as the following example:

class Product < ApplicationRecord
  has_prefix_id :prd
  self.primary_key = [:store_id, :sku]
end

The decode_prefix_id method fails to decode the composite key correctly. Specifically, when decoding the prefix_id for a Product instance, the resulting composite key array incorrectly omits the first key component.

Example to illustrate the issue:

p = Product.create(store_id: 1, sku: 10)
composite = Product.decode_prefix_id(p.prefix_id)

Currently, the composite array is:

[10]

However, the expected result should be:

[1, 10]

This fix ensures that the decode_prefix_id method properly handles composite keys, preserving all components as intended.

@excid3 excid3 merged commit a5800d2 into excid3:main Aug 1, 2024
15 checks passed
@excid3
Copy link
Owner

excid3 commented Aug 1, 2024

Thanks @plabaj 👍

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

Successfully merging this pull request may close these issues.

2 participants