# Structs
Citizen 用于示范关联模型.
Class 用于示范:
1.
No description provided by the author
primaryKey 有两个时不会生成自增主键
autoIncrement:false 标签可以显式地使主键不带 AUTO_INCREMENT 属性.
No description provided by the author
TimeRecorder 用于示范如何使用 GORM 标签和字段类型自定义存储创建时间和更新时间的字段
*/.
默认情况下,模型和关系表之间的映射关系是:
ID -> 主键
CreatedAt -> 创建时间
UpdatedAt -> 更新时间
结构体名(驼峰)的复数 -> 下划线分隔的表名
字段名(驼峰) -> 下划线分隔的列名
嵌入字段会被展开,所以为方便起见最好直接嵌入 gorm.Model
下面是该 model 在 MySQL 下对应的表,表名为 users
+------------+-----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-----------------+------+-----+---------+----------------+
| id | bigint unsigned | NO | PRI | null | auto_increment |
| created_at | datetime | YES | | null | |
| updated_at | datetime | YES | | null | |
| deleted_at | datetime | YES | MUL | null | |
| name | varchar(256) | YES | | null | |
| phone | bigint unsigned | YES | | null | |
| birthday | datetime | YES | | null | |
+------------+-----------------+------+-----+---------+----------------+
CREATE TABLE `users` (
`id` bigint unsigned AUTO_INCREMENT,
`created_at` datetime NULL,
`updated_at` datetime NULL,
`deleted_at` datetime NULL,
`name` varchar(256),
`phone` bigint unsigned,
`birthday` datetime NULL,
PRIMARY KEY (`id`),
INDEX `idx_users_deleted_at` (`deleted_at`)
);
*/.