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

feat: allow priority tag in composite PK #6784

Closed

Conversation

yaofeng-wang
Copy link

@yaofeng-wang yaofeng-wang commented Jan 7, 2024

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Fixes issue#6755 to allow priority tag for composite primary key, similar to unique index.

User Case Description

type Bad struct {
	A   ItemA
	AId uint `gorm:"primaryKey,priority:2;autoIncrement:false"`
	B   ItemB
	BId uint `gorm:"primaryKey,priority:1;autoIncrement:false"`
}

Composite primary key will be created and it follows ordering specified by priority tag:
image

@yaofeng-wang yaofeng-wang changed the title feat:allow_priority_tag_in_composite_pk feat: allow priority tag in composite PK Jan 7, 2024
@yaofeng-wang yaofeng-wang force-pushed the feat/priority_tag_for_pk branch from 1570f43 to 9107658 Compare January 7, 2024 08:49
@yaofeng-wang yaofeng-wang force-pushed the feat/priority_tag_for_pk branch from 0f6dd79 to a9c1520 Compare January 9, 2024 15:10
@jinzhu
Copy link
Member

jinzhu commented Jan 12, 2024

Why not use a unique index? Doesn't it seem more intuitive?

@yaofeng-wang
Copy link
Author

Why not use a unique index? Doesn't it seem more intuitive?

I think it's better to be able to choose between composite primary key and unique index.

@jinzhu
Copy link
Member

jinzhu commented Apr 26, 2024

We're planning to close this PR because we aim to minimize the complexity introduced by some edge cases. If necessary, we can ensure that this field is ordered in the model definition.

Thank you for your PR.

@jinzhu jinzhu closed this Apr 26, 2024
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.

Composite Primary Key should understand field priority like unique index
3 participants