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

Does bun handles Polymorphic has-one relations? #521

Open
frederikhors opened this issue Apr 22, 2022 · 4 comments
Open

Does bun handles Polymorphic has-one relations? #521

frederikhors opened this issue Apr 22, 2022 · 4 comments
Labels
question Further information is requested stale

Comments

@frederikhors
Copy link

frederikhors commented Apr 22, 2022

I'm wondering if bun today handles Polymorphic has one relation.

Example:

type Profile struct {
	ID            uint64 `bun:",pk,autoincrement"`
	TrackableID   string
	TrackableType string
	Lang          string
}

type EmployeeIdentity struct {
	ID      uint64   `bun:",pk,autoincrement"`
	Profile *Profile `bun:"rel:has-one, join:id=trackable_id, join:type=trackable_type, polymorphic"`
	Name    string
}

type CustomerIdentity struct {
	ID       uint64   `bun:",pk,autoincrement"`
	Profile  *Profile `bun:"rel:has-one, join:id=trackable_id, join:type=trackable_type, polymorphic"`
	NickName string
}

In my real code I cannot query from CustomerIdentity a Profile with Relation() and I need to execute two queries "manually".

Is there something I'm missing?

@frederikhors frederikhors changed the title Does bun handles Polymorphic has one relations? Does bun handles Polymorphic has-one relations? Apr 23, 2022
@vmihailenco
Copy link
Member

No, it does not. Perhaps you can replace with 2 ids:

type Profile struct {
	ID            uint64 `bun:",pk,autoincrement"`
	Lang          string

	Employee uint64
	Employee *EmployeeIdentity

	Customer uint64
	Customer *EmployeeIdentity
}

Maybe it should be even belongs-to relation from EmployeeIdentity and CustomerIdentity

@vmihailenco vmihailenco added the question Further information is requested label Apr 23, 2022
@frederikhors
Copy link
Author

Yeah. I'll try in a few days...

I saw that here: https://gorm.io/docs/has_one.html#Polymorphism-Association.

The thing is I have many parents, not just two...

@gaaral
Copy link

gaaral commented Oct 30, 2023

Are there any plans to support Polymorphic has one?

Copy link

github-actions bot commented Nov 7, 2024

This issue has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this issue will be closed.

@github-actions github-actions bot added the stale label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested stale
Projects
None yet
Development

No branches or pull requests

3 participants