I have this structure:
type User struct {
ID int
CreatedAt int
UpdatedAt int
DeviceUniqueIdentifier string
Sessions []Session `has_many:"sessions"`
}
I have no idea how to export this in fizz, so I did so:
buffalo pop generate model User
To my surprise, it actually generated a User and put a table in the database, but neither the table nor the structure are as expected.
Here is the new User struct:
...
type User struct {
ID uuid.UUID `json:"id" db:"id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}
...
Is there any way to generate passing some fields? Or is there a way to convert the structure to a table automatically?
There's a way to generate a model passing some fields:
buffalo pop generate model User id:int device_unique_identifier
You have to add your columns definition after the name of the model. The column syntax allows you to give the column type (by default it's considered as a string).
You'll have to add your has_many relation by hand though, relations are not yet supported by the generator.