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

Bugfix/field naming #3

Merged
merged 3 commits into from
May 12, 2023
Merged

Bugfix/field naming #3

merged 3 commits into from
May 12, 2023

Conversation

thanhpd56
Copy link
Owner

Fix 2 errors:
Error 1: When table is

Table districts {
  id bigint [pk, increment]
  code varchar(255) [not null, unique]
  name varchar(255)
  city_id bigint [ref: > cities.id, not null]
  my_city_id bigint [ref: > cities.id, not null]
  created_at datetime [not null, default: `CURRENT_TIMESTAMP`]
  updated_at datetime [not null, default: `CURRENT_TIMESTAMP`]

  Indexes {
    city_id [name: 'idx_districts_city_id']
  }
}

then the generated model contains 2 fields of Districts
After fix result will be:

// City is generated type for table 'cities'
type City struct {
	ID          int64      `json:"id" mapstructure:"id"`
	Districts   []District `gorm:"foreignkey:city_id"`
	MyDistricts []District `gorm:"foreignkey:my_city_id"`
	Name        *string    `json:"name" mapstructure:"name"`
	Code        string     `json:"code" mapstructure:"code"`
	CreatedAt   time.Time  `json:"created_at" mapstructure:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at" mapstructure:"updated_at"`
}

Error 2:
Generate column search_text_v1 to SearchText field, so if table contains 2 fields of search_text_v1, and search_text_v2, the generated model will contain 2 fields SearchText.
After fix: search_text_v1 will generate SearchTextV1 field, search_text_v2 will generate SearchTextV2 field.

@thanhpd56 thanhpd56 merged commit a7b16b3 into master May 12, 2023
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

Successfully merging this pull request may close these issues.

1 participant