Add On Delete/Update Constraint

Jinzhu 2020-06-19 23:08:02 +08:00
parent 559bae2d7f
commit 7d55bbca36
2 changed files with 34 additions and 2 deletions

@ -12,7 +12,7 @@ GORM 2.0 现处于公测阶段,已部署于多个用户的生产服务环境
* 代码模块化 * 代码模块化
* Context、批量插入、Prepared Statment、DryRun 模式、Join Preload, Find 到 Map, FindInBatches 支持 * Context、批量插入、Prepared Statment、DryRun 模式、Join Preload, Find 到 Map, FindInBatches 支持
* SavePoint/RollbackTo/Nested Transaction 支持 * SavePoint/RollbackTo/Nested Transaction 支持
* 关联关系优化多对多中间表替换优化Association 模式对批量数据支持及优化 * 关联关系优化 (On Delete/Update)多对多中间表替换优化Association 模式对批量数据支持及优化
* SQL Builder 优化, Upsert, Locking, Optimizer/Index/Comment Hints 支持 * SQL Builder 优化, Upsert, Locking, Optimizer/Index/Comment Hints 支持
* 插入时间、更新时间可支持多个字段,加入了对 unix (nano) second 的支持 * 插入时间、更新时间可支持多个字段,加入了对 unix (nano) second 的支持
* 字段多重权限支持:只读、只允许创建、只允许更新、只写、完全忽略 * 字段多重权限支持:只读、只允许创建、只允许更新、只写、完全忽略
@ -255,6 +255,22 @@ type Blog struct {
} }
``` ```
#### 关联 On Delete/Update 支持
```go
type Profile struct {
gorm.Model
Refer string
Name string
}
type User struct {
gorm.Model
Profile Profile `gorm:"Constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
ProfileID int
}
```
### 多对多中间表替换优化 ### 多对多中间表替换优化
可以更简单的来设置 `Many2Many``JoinTable`,替换后的 `JoinTable` 可获得普通模型的全部功能,例如 `Soft Delete``Hooks` 等功能支持,也可以添加更多字段 可以更简单的来设置 `Many2Many``JoinTable`,替换后的 `JoinTable` 可获得普通模型的全部功能,例如 `Soft Delete``Hooks` 等功能支持,也可以添加更多字段

@ -12,7 +12,7 @@ GORM 2.0 is not yet released, currently, in the public beta stage, it has been u
* Modularity * Modularity
* Context, Batch Insert, Prepared Statment, DryRun Mode, Join Preload, Find To Map, FindInBatches * Context, Batch Insert, Prepared Statment, DryRun Mode, Join Preload, Find To Map, FindInBatches
* SavePoint/RollbackTo/Nested Transaction Support * SavePoint/RollbackTo/Nested Transaction Support
* Association improvements, Modify Join Table for Many2Many, Association Mode for batch data * Association improvements (On Delete/Update), Modify Join Table for Many2Many, Association Mode for batch data
* SQL Builder, Upsert, Locking, Optimizer/Index/Comment Hints supports * SQL Builder, Upsert, Locking, Optimizer/Index/Comment Hints supports
* Multiple fields support for auto creating/updating time, which also support unix (nano) seconds * Multiple fields support for auto creating/updating time, which also support unix (nano) seconds
* Field permissions support: readonly, writeonly, createonly, updateonly, ignored * Field permissions support: readonly, writeonly, createonly, updateonly, ignored
@ -256,6 +256,22 @@ type Blog struct {
} }
``` ```
#### Association On Delete/Update Support
```go
type Profile struct {
gorm.Model
Refer string
Name string
}
type User struct {
gorm.Model
Profile Profile `gorm:"Constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
ProfileID int
}
```
### Modify Join Table for Many2Many ### Modify Join Table for Many2Many
Easier to setup Many2Many's `JoinTable`the `JoinTable` can be a full-featured model, like having `Soft Delete``Hooks` supports, and define more fields Easier to setup Many2Many's `JoinTable`the `JoinTable` can be a full-featured model, like having `Soft Delete``Hooks` supports, and define more fields