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

fix multiple many-to-one relationships to a table #2

Merged

Conversation

thuan1412
Copy link

Issue

We have a bug when two tables have many-to-one relationship to another table.

table users {
  id bigint [pk, increment]
}

table items {
  id bigint [pk, increment]
  user_id bigint [ref: > users.id, not null]
}

table products {
  id bigint [pk, increment]
  user_id bigint [ref: > users.id, not null]
}

With the above example, dbml-go generates the User struct with this result:

type User struct {
	ID       int64     `json:"id" mapstructure:"id"`
	Products []Product `gorm:"foreignkey:user_id"`
}

The expected result is

type User struct {
	ID       int64     `json:"id" mapstructure:"id"`
	Items    []Item    `gorm:"foreignkey:user_id"`
	Products []Product `gorm:"foreignkey:user_id"`
}

This PR resolve the above issue.

@thanhpd56 thanhpd56 merged commit 8431809 into thanhpd56:master Nov 27, 2022
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.

2 participants