Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oops the formattag remove tag #2

Closed
miclle opened this issue Apr 19, 2021 · 2 comments
Closed

Oops the formattag remove tag #2

miclle opened this issue Apr 19, 2021 · 2 comments

Comments

@miclle
Copy link

miclle commented Apr 19, 2021

The original content:

package models

import (
	"gorm.io/gorm"
)

// Location 位置,分部,办公室
type Location struct {
	ID             uint    `json:"id,omitempty"    gorm:"primaryKey"`                                           // 主建
	OrganizationID uint    `json:"organization_id" gorm:"uniqueIndex:uix_org_name"`                             // 组织 ID
	Name           string  `json:"name"            gorm:"size:255;uniqueIndex:uix_org_name" binding:"required"` // 名称
	Description    string  `json:"description"     gorm:"type:text"`                                            // 描述
	Avatar         string  `json:"avatar"`                                                                      // LOGO
	Address        string  `json:"address"`                                                                     // 地址
	ZipCode        string  `json:"zip_code"`                                                                    // 邮政编码
	Phone          string  `json:"phone"`                                                                       // 电话号码
	Fax            string  `json:"fax"`                                                                         // 传真
	Position       float64 `json:"position"`                                                                    // 排序位置

	CreatedAt int64 `json:"created_at,omitempty"` // 创建时间
	UpdatedAt int64 `json:"updated_at,omitempty"` // 更新时间

	CountMembers int `json:"count_members" sql:"-"`
}

// AfterCreate gorm after create Callback
func (location *Location) AfterCreate(tx *gorm.DB) (err error) {
	err = tx.UpdateColumn("position", location.ID).Error
	return
}

After run formattag:

package models

import (
	"gorm.io/gorm"
)

// Location 位置,分部,办公室
type Location struct {
	ID             uint    `json:"id,omitempty"    gorm:"primaryKey"`                                           // 主建
	OrganizationID uint    `json:"organization_id" gorm:"uniqueIndex:uix_org_name"`                             // 组织 ID
	Name           string  `json:"name"            gorm:"size:255;uniqueIndex:uix_org_name" binding:"required"` // 名称
	Description    string  `json:"description"     gorm:"type:text"`                                            // 描述
	Avatar         string  `json:"avatar"`                                                                      // LOGO
	Address        string  `json:"address"`                                                                     // 地址
	ZipCode        string  `json:"zip_code"`                                                                    // 邮政编码
	Phone          string  `json:"phone"`                                                                       // 电话号码
	Fax            string  `json:"fax"`                                                                         // 传真
	Position       float64 `json:"position"`                                                                    // 排序位置

	CreatedAt int64 `json:"created_at,omitempty"` // 创建时间
	UpdatedAt int64 // 更新时间

	CountMembers int `json:"count_members" sql:"-"`
}

// AfterCreate gorm after create Callback
func (location *Location) AfterCreate(tx *gorm.DB) (err error) {
	err = tx.UpdateColumn("position", location.ID).Error
	return
}
@momaek
Copy link
Owner

momaek commented Apr 19, 2021

fixed.

@momaek
Copy link
Owner

momaek commented Apr 19, 2021

Use lastest version

@momaek momaek closed this as completed Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants