Fix many-to-many relationship queries with custom schema linking objects#3106
Fix many-to-many relationship queries with custom schema linking objects#3106
Conversation
|
@copilot why is the PR not published yet? |
The PR is published and ready for review. The branch |
|
@copilot the PR is still in draft state. |
I don't have the ability to change the PR from draft to ready for review. This requires marking the PR as "Ready for review" in the GitHub UI. A maintainer or the PR author would need to click the "Ready for review" button on the PR page to publish it. |
There was a problem hiding this comment.
Pull request overview
Fixes SQL Server GraphQL many-to-many relationship failures when the linking object is in a non-dbo schema by making DatabaseObject equality/hash behavior case-insensitive so FK lookups succeed despite casing differences between config and database metadata.
Changes:
- Update
DatabaseObject.Equals()to useStringComparison.OrdinalIgnoreCasefor schema/object name comparisons. - Update
DatabaseObject.GetHashCode()to align with case-insensitive equality. - Add a unit test intended to cover many-to-many relationships with linking objects in custom schemas and varying casing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Config/DatabasePrimitives/DatabaseObject.cs | Makes DatabaseObject equality case-insensitive to prevent FK lookup misses due to casing. |
| src/Service.Tests/UnitTests/ConfigValidationUnitTests.cs | Adds a new data-driven test for custom-schema linking objects in M:N relationships. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| /// is in a custom schema (not dbo). This test validates that schema names are correctly compared | ||
| /// using case-insensitive comparison, which is important for SQL Server where schema names are | ||
| /// case-insensitive. | ||
| /// </summary> |
There was a problem hiding this comment.
@copilot : Consider also casing-mismatching expectedLinkingTable (not just the source tables) so the test always fails if DatabaseTable.Equals becomes case-sensitive again.
There was a problem hiding this comment.
Updated expectedLinkingTable to use .ToLowerInvariant() for both schema and table name, ensuring the test fails if DatabaseTable.Equals becomes case-sensitive again. Commit 0f2a111.
| /// is in a custom schema (not dbo). This test validates that schema names are correctly compared | ||
| /// using case-insensitive comparison, which is important for SQL Server where schema names are | ||
| /// case-insensitive. | ||
| /// </summary> |
There was a problem hiding this comment.
@copilot Add a Verify(..., Times.Never) to assert VerifyForeignKeyExistsInDB is never called with a DatabaseTable whose SchemaName is dbo, so the test explicitly guards against the original dbo-fallback regression.
There was a problem hiding this comment.
Added two Verify(..., Times.Never) calls to assert that VerifyForeignKeyExistsInDB is never called with a DatabaseTable whose SchemaName is dbo, guarding against the original dbo-fallback regression. Commit 0f2a111.
…verification Co-authored-by: anushakolan <45540936+anushakolan@users.noreply.github.com>
Why make this change?
GraphQL queries with M:N relationships fail with SQL error 208 ("Invalid object name") when the linking object uses a custom schema (e.g.,
"linkingObject": "mySchema.books_authors"). The query works only if a table with the same name exists indbo.What is this change?
DatabaseObject.Equals()andGetHashCode()used case-sensitive string comparison. SQL Server schema/table names are case-insensitive, causing FK definition lookups to fail when database-returned names differ in casing from config-specified names.StringComparison.OrdinalIgnoreCaseforEquals()andStringComparer.OrdinalIgnoreCase.GetHashCode()forGetHashCode()How was this tested?
Added
TestRelationshipWithLinkingObjectInCustomSchemawith test cases for:mySchema.TEST_SOURCE_LINK)MYSCHEMA.TEST_SOURCE_LINK)myschema.test_source_link)The test uses case-mismatched
DatabaseTableinstances (linking table with lowercase, source tables with uppercase) to ensure the test fails ifDatabaseTable.Equalsbecomes case-sensitive again. Additionally,Verify(..., Times.Never)assertions guard against the original dbo-fallback regression by assertingVerifyForeignKeyExistsInDBis never called with aDatabaseTablewhoseSchemaNameisdbo.Sample Request(s)
With config:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.