fix(db-postgres): find custom id field from flattened fields for FK type#17123
Open
alphanull wants to merge 1 commit into
Open
fix(db-postgres): find custom id field from flattened fields for FK type#17123alphanull wants to merge 1 commit into
alphanull wants to merge 1 commit into
Conversation
When a collection defines a custom text or number id field nested inside a layout container (row, group, collapsible, tabs), traverseFields used a shallow Array.find on collection.fields to determine the FK column type. Layout containers have no name property so fieldAffectsData returns false, causing the nested id field to be skipped and FK columns to default to integer. This caused a hard startup crash when the referenced collection used a varchar primary key. Fix: use flattenAllFields (already exported from payload/shared and used for the same purpose in db-mongodb since v3.71.0) before searching for the custom id field, matching the fix from PR payloadcms#15110. Fixes payloadcms#13695
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
When a collection defines a custom
textornumberid field nested inside a layout container (row,group,collapsible, ortabs),traverseFieldsin@payloadcms/drizzleused a shallowArray.findoncollection.fieldsto determine the FK column type for relationship fields.Layout containers have no
nameproperty, sofieldAffectsDatareturnsfalsefor them — the nestedidfield is never reached, and FK columns default tointeger. This causes a hard startup crash when the referenced collection uses avarcharprimary key:Why?
traverseFieldsin the Drizzle adapter needs to find the customidfield of a related collection to determine the correct FK column type. The shallowfindworks only whenidis at the top level offields. Any layout wrapper breaks detection.How?
Use
flattenAllFields(already exported frompayload/shared) before searching for the customidfield — identical to the fix applied todb-mongodbin PR #15110 (v3.71.0). This covers all layout containers:row,group,collapsible, andtabs.Checklist
test/relationships— newcustomIdRowSlugcollection withidnested intype: 'row', regression test verifies create/read works without FK type mismatch)59 passed, 0 failedagainst Postgres)Closes #13695