You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test: verify synchronize true works with multiple relations - #11889
Added tests for issue #7738. I attempted to replicate the issue, but everything functioned properly.
Also add one test as specified at #7738 (comment).
Pull-Request Checklist
Code is up-to-date with the master branch
This pull request links relevant issues as Fixes #00000
There are new or updated tests validating the change (tests/**.test.ts)
Documentation has been updated to reflect this change (docs/docs/**.md)
Test uses PostgreSQL driver (enabledDrivers: ["postgres"])
Test includes Professor and Subject entities with multiple relations to same table
Test verifies that second synchronization does not fail (await expect(dataSource.synchronize()).to.not.be.rejected)
Test creates and saves entities to verify foreign key relationships work correctly
Requires further human verification:
Whether the test actually reproduces the original bug condition (the PR description states "I attempted to replicate the issue, but everything functioned properly")
The test includes Site and SiteLocation entities which test a OneToOne relationship, but these entities are not mentioned in the original issue #7738. The issue specifically describes a problem with multiple ManyToOne relations to the same table. While additional test coverage is good, it's unclear if these entities are necessary for reproducing the specific bug or if they add unrelated test scenarios.
The Professor entity has synchronize: true explicitly set in the @Entity decorator, but the Site and SiteLocation entities do not. This inconsistency might affect test behavior. Either all entities should have explicit synchronize settings or none should, to ensure consistent test conditions.
Replace the to.not.be.rejected assertion with the more idiomatic to.be.fulfilled from chai-as-promised to assert that the promise resolves successfully.
it("should not fail with constraint already exists error when synchronizing multiple times", () =>
Promise.all(
connections.map(async (dataSource) => {
// First synchronization
await dataSource.synchronize()
// Second synchronization should not fail with constraint error
- await expect(dataSource.synchronize()).to.not.be.rejected+ await expect(dataSource.synchronize()).to.be.fulfilled
...
}),
))
[To ensure code accuracy, apply this suggestion manually]
Suggestion importance[1-10]: 3
__
Why: The suggestion correctly points out that to.be.fulfilled is a more idiomatic assertion for promise success, but the existing code with to.not.be.rejected is also valid and functional, making this a low-impact style improvement.
Add explicit expect checks to verify that the professor and assistant relations on loadedSubject are not null or undefined before accessing their properties.
Why: Adding explicit checks for the existence of the professor and assistant relations makes the test more robust and provides clearer failure messages if the relations are not loaded correctly.
Low
Possible issue
Fix invalid Chai assertion syntax
Replace the to.not.be.rejected Chai assertion with to.be.fulfilled for better readability when checking for a successful promise resolution.
// Second synchronization should not fail with constraint error
-await expect(dataSource.synchronize()).to.not.be.rejected+await expect(dataSource.synchronize()).to.be.fulfilled
Suggestion importance[1-10]: 3
__
Why: The assertion to.not.be.rejected is valid with chai-as-promised and works correctly, but using to.be.fulfilled is more direct and slightly improves readability.
it("should not fail with constraint already exists error when synchronizing multiple times", () =>
Promise.all(
connections.map(async (dataSource) => {
// First synchronization
await dataSource.synchronize()
// Second synchronization should not fail with constraint error
- await expect(dataSource.synchronize()).to.not.be.rejected+ await expect(dataSource.synchronize()).to.be.fulfilled
Suggestion importance[1-10]: 4
__
Why: The suggestion correctly identifies that to.be.fulfilled is a more explicit and idiomatic assertion than to.not.be.rejected for this test case, improving code clarity.
Remove the unrelated test logic for Site and SiteLocation to make the test more focused on its primary goal of verifying synchronization with multiple foreign keys.
Why: The suggestion correctly identifies that the test code for Site and SiteLocation is not relevant to the test's primary goal, and removing it would improve the test's focus and maintainability.
Low
Use modern object-based relations syntax
Update the relations option in subjectRepo.findOne to use the modern object-based syntax instead of the deprecated string array.
Why: The suggestion correctly proposes updating the deprecated string-based relations syntax to the modern object-based syntax, which improves code style and aligns with current best practices.
Qodo reviewed your code and found no material issues that require review
gioboa
changed the title
test: add tests to verify that synchronize: true is working perfectly with multiple relations
test: verify synchronize true works with multiple relations
Jan 13, 2026
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
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.
Description of change
Added tests for issue #7738. I attempted to replicate the issue, but everything functioned properly.
Also add one test as specified at #7738 (comment).
Pull-Request Checklist
masterbranchFixes #00000tests/**.test.ts)docs/docs/**.md)