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
Since all users have the same manager, the manager only needs to be created once and referenced via its ID in users 1-3. However, this does not work as expected when using
The manager is assigned an ID based on BeforeCreate and gorm creates it with the same ID for every user (3 times).
This is not a problem for MariaDB or Postgres, as they simply ignore the superfluous, identical users. For MS SQL (sqlserver), however, it is a problem as it refuses to create multiple tuples with the same ID and therefore rejects all three users (no rows are inserted).
As the manager is not created but referenced in the next SQL statement (creation of users 1-3), an error occurs as the referenced manager is missing.
Expected behavior:
Gorm should create a SQL statement to insert only one manager.
Actual behavior:
Gorm creates a sql statement to insert a manager for each user, even if it is the same for each user.
Additional information
Database: MSSQL
Go version: 1.23.3
The text was updated successfully, but these errors were encountered:
GORM Playground Link
go-gorm/playground#788
Description
I use the terms from the playground to explain this:
Multiple users have the same manager.
Since all users have the same manager, the manager only needs to be created once and referenced via its ID in users 1-3. However, this does not work as expected when using
The manager is assigned an ID based on
BeforeCreate
and gorm creates it with the same ID for every user (3 times).This is not a problem for MariaDB or Postgres, as they simply ignore the superfluous, identical users. For MS SQL (sqlserver), however, it is a problem as it refuses to create multiple tuples with the same ID and therefore rejects all three users (no rows are inserted).
As the manager is not created but referenced in the next SQL statement (creation of users 1-3), an error occurs as the referenced manager is missing.
Expected behavior:
Gorm should create a SQL statement to insert only one manager.
Actual behavior:
Gorm creates a sql statement to insert a manager for each user, even if it is the same for each user.
Additional information
Database: MSSQL
Go version: 1.23.3
The text was updated successfully, but these errors were encountered: