Skip to content

hlxwell/gorm-by-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GORM by Example

This project is for give examples for how to use GORM to do CRUD.

Features

  • Load Fixture
  • Scope
  • Many to many
  • Has Many
  • JSON Field
  • Validate

JSON Field

Callback Notes

many2many 的中间表 callback 不太好用。所以需要通过自己写 Delete 方法来 cover callback。 比如在例子中 user_role 属于中间表,你在 user_role 里面添加 AfterDelete 的时候,期待他被删除的时候会被触发,其实不会。

user.Destroy() => 会删除所有的 user 的关联表func (user *User) Destroy() {
  // 删除所有的 associated objects
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages