Files
go-admin/template
zhangwenjian d53c8abc6c fix🐛: generate a model and DTOs for any single-column primary key
The model and DTO templates assumed every table's key is an int column named
id. For any other key the generated backend did not compile - the model
embedded models.Model, which supplies Id, skipped the real key column, and
GetId then returned a field that did not exist ("e.Code undefined"). Past the
compile error there was more of the same assumption:

  - GetReq and UpdateReq bound the key with uri:"<json field>", while every
    generated router registers it as :id, so any other name bound nothing;
  - InsertReq tagged the key json:"-", so a key the database does not assign,
    such as a string, could never be supplied;
  - DeleteReq took Ids []int, so a string key could not be deleted.

models.Model now stands in for the key only when the key is exactly an int
named Id; anything else is declared as its own primaryKey field. The key is
bound from :id, accepted from the request body when it is not an int, and
deleted by a list of its own type. A table keyed on an int id renders
byte-for-byte as before.
2026-09-25 19:59:59 +08:00
..
2021-07-14 11:48:40 +08:00
2021-03-07 15:37:14 +08:00