Skip to content

It's possible to shorten table relation aliases? #566

Answered by un-versed
un-versed asked this question in Q&A
Discussion options

You must be logged in to vote

I found a way to do this:

type TheNameOfStructInPrivCodebase struct {
	bun.BaseModel          `bun:"table:the_name_of_table_in_the_database,alias:osih"`
	ID                     int64     `json:"id" bun:"id,pk,autoincrement"`
	TheNameOfSecondTableID int64     `json:"the_name_of_second_table_id"`
	CreatedAt              time.Time `json:"created_at" bun:",nullzero,notnull,default:current_timestamp"`
	UpdatedAt              time.Time `json:"updated_at" bun:",nullzero,notnull,default:current_timestamp"`
	// Relationships
	TheNameOfSecondStruct *TheNameOfSecondStruct `json:"the_name_of_second_table" bun:"osi,rel:belongs-to,join:the_name_of_second_table_id=id"`
}

type TheNameOfSecondStruct struct

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by un-versed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant