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

Relation with custom column name cause a panic because it doesn't find that column name #509

Closed
mxmaxime opened this issue Apr 8, 2022 · 5 comments
Labels

Comments

@mxmaxime
Copy link

mxmaxime commented Apr 8, 2022

Hi,
FYI I use bun to query an existing database, no way to change things on it.

  • version: latest

Here's a little example:

type BlablaModel struct {
  ID uint64 `bun:"SomeId,pk"`
  Stuff []*StuffModel `bun:"rel:has-many,join:SomeId=id"`
}

And I get this error:

A panic occurred and has been caught: bun: BlablaModel has-many Stuff: BlablaModel must have column SomeId

The panic raise is coming from schema/table.go#632

It might be linked of some case sensitivity? Idk, I dug but I didn't find the root cause.
I saw your kind warning here but.. I need that column to contains those case-sensitive str.
Do you have an idea?
Thanks!

@vmihailenco
Copy link
Member

Try join:some_id=id and make sure you have column with the name some_id.

@mxmaxime
Copy link
Author

mxmaxime commented Apr 9, 2022

but what if I don't have a column some_id in the db and I can't actually add this column in the schema?

@vmihailenco
Copy link
Member

Then this is not a has-many relation and you should not use rel:has-many,join:SomeId=id. It is hard to tell what you are trying to achieve.

@mxmaxime
Copy link
Author

mxmaxime commented Apr 9, 2022

Well, it's a has-many relation ship.
But, the actual column name on the left side is SomeId on the database and I can't change it.

The table looks like:

CREATE TABLE BlablaModel
(
    SomeId INT PRIMARY KEY NOT NULL,
....
)

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
@j2gg0s j2gg0s closed this as completed Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants