Fix composite FK column mapping in generated from methods (#148)#149
Merged
oyvindberg merged 3 commits intomainfrom Jul 8, 2025
Merged
Fix composite FK column mapping in generated from methods (#148)#149oyvindberg merged 3 commits intomainfrom
oyvindberg merged 3 commits intomainfrom
Conversation
- Created issue148.sql with minimal reproduction case - Added test tables for the foreign key mapping issue - Updated install.sh to include the new SQL file - Generated code showing the FK mapping problem The issue: When generating TestInsert code for composite foreign keys, the generated code incorrectly maps FK columns. 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
Fixed incorrect column mapping in composite foreign key `from` methods. The issue was that ColsFromFk was simply zipping columns by position instead of matching them correctly based on the FK relationship. Key changes: - Added candidateFk parameter to ColsFromFk to access FK constraint info - Modified colPairs logic to map columns by FK relationship, not position - Fixed column mapping to correctly match FK cols with otherCols Before: utdanningsmulighetKode = TestUtdanningstilbudId.organisasjonskode After: utdanningsmulighetKode = TestUtdanningstilbudId.utdanningsmulighetKode The fix ensures that FK columns are properly matched with their corresponding fields in the referenced composite ID type based on the actual foreign key constraint definition. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
745ab12 to
ef6619d
Compare
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.
Summary
Fixes #148 - Fixed incorrect column mapping in composite foreign key
frommethods whereColsFromFkwas simply zipping columns by position instead of matching them correctly based on the FK relationship.Problem
When generating
frommethods in composite ID companion objects, the column mapping from foreign key composite IDs was incorrect. For example:Before (incorrect):
After (correct):
Root Cause
In
FkAnalysis.scala, theColsFromFk.colPairsmethod was usingotherCompositeId.cols.toList.zip(thisColumns)which matched columns by position, not by their actual FK relationship.Solution
candidateFkparameter toColsFromFkto access FK constraint informationcolPairslogic to map columns based on FK constraint relationship:candidateFk.thisFk.colscandidateFk.thisFk.otherColsotherCompositeId.colsby nameChanges
typo/src/scala/typo/internal/FkAnalysis.scalatests/src/scala/typo/internal/FkAnalysisTest.scalaCLAUDE.mdwith general development workflow🤖 Generated with Claude Code