Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CreateTableQuery: Small cleanups for foreign key handling #941

Merged
merged 5 commits into from
Jan 10, 2024

Conversation

bevzzz
Copy link
Collaborator

@bevzzz bevzzz commented Dec 17, 2023

These are just some cosmetic changes I've stumbled upon while working on another ticket:

  • swapped HasOneRelation and BelongsToRelation places, so that the type is set correctly. That did not affect the functionality, but could prevent some obscure bugs in the future.
  • added a References() bool method to Relation to highlight the difference between the ones that need a FOREIGN KEY clause themselves and the ones that are referenced by other tables instead.
  • idempotent .WithForeignKeys()

@bevzzz bevzzz changed the title Small groom for Relation.Type logic CreateTableQuery: Small cleanups for foreign key handling Dec 17, 2023
query_table_create.go Outdated Show resolved Hide resolved
bevzzz added a commit to bevzzz/bun that referenced this pull request Jan 7, 2024
bevzzz added 5 commits January 7, 2024 14:04
HasOneRelation and BelongsToRelation aren't checked anywhere at the moment,
but the change is necessary to avoid any hidden bugs in the future.
+ Document the logic for omitting the clause for some Relations

The name References() is derived from the REFERENCES keyword
used to declare an FK constraint
Subsequent calls to WithForeignKeys() should not create additional
FOREIGN KEY clauses in the query.

DBs probably have no problem dealing with duplicated FKs, but
this behaviour is hardly expected / relied on by anyone.
@bevzzz bevzzz force-pushed the chore/relations_cleanup branch from 90e75bf to c0aa6a8 Compare January 7, 2024 13:08
@vmihailenco vmihailenco merged commit 4785291 into uptrace:master Jan 10, 2024
3 checks passed
@bevzzz bevzzz deleted the chore/relations_cleanup branch January 10, 2024 09:11
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.

2 participants