Thanks to visit codestin.com
Credit goes to github.com

Skip to content

test(query-builder): joins should include database schema in table name in the generated query#12062

Draft
Cprakhar wants to merge 1 commit intotypeorm:masterfrom
Cprakhar:test/7053
Draft

test(query-builder): joins should include database schema in table name in the generated query#12062
Cprakhar wants to merge 1 commit intotypeorm:masterfrom
Cprakhar:test/7053

Conversation

@Cprakhar
Copy link
Contributor

@Cprakhar Cprakhar commented Mar 2, 2026

Description of change

This PR adds tests for #7053

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links relevant issues as Related #7053
  • There are new or updated tests validating the change (tests/**.test.ts)
  • Documentation has been updated to reflect this change (docs/docs/**.md) (N/A)

@qodo-free-for-open-source-projects

Review Summary by Qodo

Add tests for schema-qualified joins in query builder

🧪 Tests

Grey Divider

Walkthroughs

Description
• Add comprehensive tests for schema-qualified joins in query builder
• Test schema inclusion in regular inner joins with multiple entities
• Test schema inclusion in subquery joins with nested relationships
• Verify correct SQL generation with proper schema prefixes
Diagram
flowchart LR
  A["Test Suite"] --> B["Regular Join Test"]
  A --> C["Subquery Join Test"]
  B --> D["Verify Schema in SQL"]
  C --> D
  D --> E["Validate Query Execution"]
Loading

Grey Divider

File Changes

1. test/functional/multi-schema-and-database/custom-schema-joins/custom-schema-joins.test.ts 🧪 Tests +106/-0

Main test suite for schema-qualified joins

• Created test suite for multi-schema joins with two test cases
• First test validates schema inclusion in regular inner joins between Lesson, _StudyPlanCourse, and
 Course entities
• Second test validates schema inclusion in subquery joins with nested relationships
• Both tests verify SQL generation contains proper schema-qualified table names and execute
 successfully

test/functional/multi-schema-and-database/custom-schema-joins/custom-schema-joins.test.ts


2. test/functional/multi-schema-and-database/custom-schema-joins/entity/Course.ts 🧪 Tests +10/-0

Course entity with custom schema

• Define Course entity with schema "myschema"
• Include id as primary column and name as regular column

test/functional/multi-schema-and-database/custom-schema-joins/entity/Course.ts


3. test/functional/multi-schema-and-database/custom-schema-joins/entity/Lesson.ts 🧪 Tests +13/-0

Lesson entity with custom schema

• Define Lesson entity with schema "myschema"
• Include auto-generated id, courseId foreign key, and duration columns

test/functional/multi-schema-and-database/custom-schema-joins/entity/Lesson.ts


View more (2)
4. test/functional/multi-schema-and-database/custom-schema-joins/entity/StudyPlan.ts 🧪 Tests +10/-0

StudyPlan entity with custom schema

• Define StudyPlan entity with schema "myschema"
• Include id as primary column and name as regular column

test/functional/multi-schema-and-database/custom-schema-joins/entity/StudyPlan.ts


5. test/functional/multi-schema-and-database/custom-schema-joins/entity/_StudyPlanCourse.ts 🧪 Tests +10/-0

Junction entity for study plan courses

• Define _StudyPlanCourse junction entity with schema "myschema"
• Include composite primary key with studyPlanId and courseId columns

test/functional/multi-schema-and-database/custom-schema-joins/entity/_StudyPlanCourse.ts


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Remediation recommended

1. Unneeded IDENTITY_INSERT path 🐞 Bug ⛯ Reliability
Description
The test inserts Lesson rows with an explicit id even though id is
@PrimaryGeneratedColumn(). On MSSQL this causes TypeORM to wrap the INSERT in `SET IDENTITY_INSERT
... ON/OFF`, which is unrelated to the join-schema behavior being tested and can introduce avoidable
brittleness.
Code

test/functional/multi-schema-and-database/custom-schema-joins/custom-schema-joins.test.ts[R36-38]

+                await connection
+                    .getRepository(Lesson)
+                    .save({ id: 1, courseId: "c1", duration: 60 })
Evidence
The test explicitly sets id: 1 for Lesson even though the entity uses an auto-generated primary
key. TypeORM has explicit logic to enable IDENTITY_INSERT on MSSQL when an explicit value is
provided for an auto-increment PK, meaning this test will execute extra MSSQL-specific statements as
part of its setup.

test/functional/multi-schema-and-database/custom-schema-joins/custom-schema-joins.test.ts[36-38]
test/functional/multi-schema-and-database/custom-schema-joins/custom-schema-joins.test.ts[72-75]
test/functional/multi-schema-and-database/custom-schema-joins/entity/Lesson.ts[3-6]
src/query-builder/InsertQueryBuilder.ts[755-773]
src/query-builder/InsertQueryBuilder.ts[1008-1025]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The tests insert `Lesson` entities with an explicit `id` even though `Lesson.id` is a `@PrimaryGeneratedColumn()`. On MSSQL, this triggers TypeORM to wrap inserts with `SET IDENTITY_INSERT ... ON/OFF`, adding extra MSSQL-specific statements and potential brittleness unrelated to the join-schema assertions.

### Issue Context
The tests only need `courseId` and `duration` to validate join generation and query results; `id` is not used.

### Fix Focus Areas
- test/functional/multi-schema-and-database/custom-schema-joins/custom-schema-joins.test.ts[36-38]
- test/functional/multi-schema-and-database/custom-schema-joins/custom-schema-joins.test.ts[72-75]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@Cprakhar Cprakhar marked this pull request as draft March 2, 2026 13:09
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.

1 participant