GORM Playground Link
https://github.com/go-gorm/playground/pull/588
Description
When the primary key is a UUID that is generated on the database create object can't find primaryKey Field.
as mentioned at #5320
Comment From: a631807682
https://gorm.io/docs/query.html#Retrieving-objects-with-primary-key
If the primary key is a string (for example, like a uuid), the query will be written as follows:
db.First(&user, "id = ?", "1b74413f-f3b8-409f-ac47-e8c062e3472a") // SELECT * FROM users WHERE id = "1b74413f-f3b8-409f-ac47-e8c062e3472a";
When the type is string, we cannot determine whether the user is using the primary key or the condition of the sql statement.
Comment From: onurhuseyincantay
@a631807682 I was referring for object creation I reused the existing Create function on the test case this is after creation.
Comment From: onurhuseyincantay
@a631807682 after some investigation I made my local version work and the reasoning is below:
// Fails
type User struct {
Languages []Language `gorm:"many2many:Languages"`
}
// Succeeds
type User struct {
Languages []Language `gorm:"many2many:UserSpeaks"`
}
so what happens is that the many2many table name has to be unique even a plural version of the table doesn't work.
Comment From: onurhuseyincantay
CC: @jinzhu, since @a631807682 is on vacation.
Comment From: a631807682
https://gorm.io/docs/conventions.html#Pluralized-Table-Name I didn't understand your question. By default, a table with a plural name will be created, indicating that it cannot have the same name as a relational table.
Comment From: onurhuseyincantay
That I realized, but dont you think many2many relationship based variable would most probably also named as plural and this will cause error. I would suggest to not even migrate a table and check if the many2many table name on the flags is correct so the consumer of gorm can identify the issue.