It seems that nested structs without db tag are not omitted on insert or update. Is this a bug or do I need to set a specific db tag to ignore nested structs?
An example, a user struct with a current house set, and a house struct.
type User struct {
ID int32 `db:"id,omitempty"`
Username string `db:"username"`
Password sql.NullString `db:"password"`
Email string `db:"email"`
ApiToken string `db:"apiToken"`
CurrentHouseID int32 `db:"currentHouse_id"`
CurrentHouse house # Should be ignored for upper/db because no `db:",inline"` or similar set
Houses []House
}
type House struct {
ID int32 `db:"id,omitempty"`
Name string `db:"name"`
State bool `db:"state"`
CreateDate time.Time `db:"createDate"`
CreateUserID sql.NullInt32 `db:"createUser_id"`
EditDate sql.NullTime `db:"editDate"`
EditUserID sql.NullInt32 `db:"editUser_id"`
}
If I remove nested struct CurrentHouse from User everything works fine. But if I add CurrentHouse update query fails to execute because all fields of House are added to this query, when using sess.SQL().Update("user1").Set(&user).Where("id = ?", id)
Installed version: 4.6.0 DB: mysql
It seems that nested structs without db tag are not omitted on insert or update. Is this a bug or do I need to set a specific db tag to ignore nested structs?
An example, a user struct with a current house set, and a house struct.
If I remove nested struct
CurrentHouse
fromUser
everything works fine. But if I add CurrentHouse update query fails to execute because all fields ofHouse
are added to this query, when usingsess.SQL().Update("user1").Set(&user).Where("id = ?", id)
Struct
User
does not have fields set like createDate, createUser_id,...