fix: include joined entity primary keys in pagination subquery by mag123c · Pull Request #11669 · typeorm/typeorm
PR Code Suggestions ✨
Latest suggestions up to 9064fa0
| Category | Suggestion | Impact |
| Possible issue |
Verify all composite primary keysTo ensure correct grouping for composite primary keys, change the check from src/query-builder/transformer/RawSqlResultsToEntityTransformer.ts [117-120] -// Check if primary key columns are actually selected in the raw results -const primaryKeysSelected = keys.some( +// Check if all primary key columns are actually selected in the raw results +const primaryKeysSelected = keys.every( (key) => key in (rawResults[0] ?? {}), )
Suggestion importance[1-10]: 9__ Why: Using | High |
| General |
Handle empty results arrayAdd a check to handle an empty src/query-builder/transformer/RawSqlResultsToEntityTransformer.ts [117-122] +// Handle empty results +if (rawResults.length === 0) { + return map +} + // Check if primary key columns are actually selected in the raw results const primaryKeysSelected = keys.some( - (key) => key in (rawResults[0] ?? {}), + (key) => key in rawResults[0], ) for (const rawResult of rawResults) {
Suggestion importance[1-10]: 4__ Why: The suggestion correctly identifies a potential issue with an empty | Low |
| ||
Previous suggestions
Suggestions up to commit 5429b85
| Category | Suggestion | Impact |
| Possible issue |
Validate all primary keys existTo ensure correct entity grouping with composite primary keys, change the check src/query-builder/transformer/RawSqlResultsToEntityTransformer.ts [117-120] // Check if primary key columns are actually selected in the raw results -const primaryKeysSelected = keys.some( - (key) => key in (rawResults[0] ?? {}), -) +const primaryKeysSelected = rawResults.length > 0 && + keys.every((key) => key in rawResults[0]) Suggestion importance[1-10]: 7__ Why: The suggestion correctly identifies that using | Medium |
Suggestions up to commit dae49c7
| Category | Suggestion | Impact |
| General |
Optimize row index lookup performanceReplace the inefficient src/query-builder/transformer/RawSqlResultsToEntityTransformer.ts [142-147] +} else { + // Fallback: use row index when primary keys are not available + // This ensures each row gets its own group for proper entity mapping + const rowIndex = rawResults.indexOf(rawResult) + id = `row_${rowIndex}` +} - Suggestion importance[1-10]: 6__ Why: The suggestion correctly identifies a performance issue where using | Low |
Suggestions up to commit f94b754
| Category | Suggestion | Impact |
| Possible issue |
Validate all composite primary keysReplace src/query-builder/transformer/RawSqlResultsToEntityTransformer.ts [118-125] const hasValidKeys =
keys.length > 0 &&
rawResults.length > 0 &&
- keys.some(
+ keys.every(
(key) =>
rawResults[0].hasOwnProperty(key) &&
rawResults[0][key] !== undefined,
)Suggestion importance[1-10]: 8__ Why: The suggestion correctly identifies a bug in the new | Medium |
Suggestions up to commit 9ddcf86
| Category | Suggestion | Impact |
| Possible issue |
Validate all composite primary keysReplace src/query-builder/transformer/RawSqlResultsToEntityTransformer.ts [118-125] const hasValidKeys =
keys.length > 0 &&
rawResults.length > 0 &&
- keys.some(
+ keys.every(
(key) =>
rawResults[0].hasOwnProperty(key) &&
rawResults[0][key] !== undefined,
)Suggestion importance[1-10]: 8__ Why: The suggestion correctly identifies that using | Medium |
Suggestions up to commit 17cab60
| Category | Suggestion | Impact |
| Possible issue |
Validate all composite primary keysChange src/query-builder/transformer/RawSqlResultsToEntityTransformer.ts [118-125] const hasValidKeys =
keys.length > 0 &&
rawResults.length > 0 &&
- keys.some(
+ keys.every(
(key) =>
rawResults[0].hasOwnProperty(key) &&
rawResults[0][key] !== undefined,
)Suggestion importance[1-10]: 8__ Why: The suggestion correctly identifies that using | Medium |
| General |
Optimize row index lookup performanceOptimize the row index lookup by replacing the src/query-builder/transformer/RawSqlResultsToEntityTransformer.ts [147-152] +} else { + // Fallback: use row index when primary keys are not available + // This ensures each row gets its own group for proper entity mapping + const rowIndex = rawResults.indexOf(rawResult) + id = `row_${rowIndex}` +} - Suggestion importance[1-10]: 6__ Why: The suggestion correctly points out a performance issue with O(n²) complexity by using | Low |