You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can't get an m2m relation to work, though it is nearly the same as the example one.
It is firing somewhere in the ParkStruct() function in the hydration phase during the join read.
"Order" is "App" here, and "Item" is "Group" here, and one subtle difference is that each group must belong to an app,
so even before the join, every group already has an app_id.
After inserting a simple INSERT INTO apps_default_groups (app_id, group_id) VALUES (1, 1); into the relation table in Postgres, the error when fetching an app with ID 1 and .WithRelation("DefaultGroups") is: bun: m2m relation=DefaultGroups does not have base model=App with key=['\x01' '\x01'] (check join conditions)
Could somebody please give me some hint what I have to fix?
My models are roughly:
type App struct {
bun.BaseModel `bun:"table:apps"`
Id int64 `bun:"id,pk,autoincrement"`
Name string `bun:"name"`
Groups []Group `bun:"rel:has-many,join:id=app_id"`
DefaultGroups []Group `bun:"m2m:apps_default_groups,join:App=Group"` // I don't understand this join syntax, but If I change something here, bun complains that it cannot find the field in the relation model
}
type Group struct {
bun.BaseModel `bun:"table:groups"`
Id int64 `bun:"id,pk,autoincrement"`
AppId int64 `bun:"app_id"`
App *App `bun:"rel:belongs-to,join:app_id=id"`
Name string `bun:"name"`
}
type AppToDefaultGroup struct {
bun.BaseModel `bun:"table:apps_default_groups"` // without this, registerModel() cannot find a mapping to the table name
AppId int64 `bun:"app_id,pk"`
App *App `bun:"rel:belongs-to,join:app_id=id"`
GroupId int64 `bun:"group_id,pk"`
Group *Group `bun:"rel:belongs-to,join:group_id=id"`
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I can't get an m2m relation to work, though it is nearly the same as the example one.
It is firing somewhere in the
ParkStruct()
function in the hydration phase during the join read."Order" is "App" here, and "Item" is "Group" here, and one subtle difference is that each group must belong to an app,
so even before the join, every group already has an
app_id
.After inserting a simple
INSERT INTO apps_default_groups (app_id, group_id) VALUES (1, 1);
into the relation table in Postgres, the error when fetching an app with ID 1 and.WithRelation("DefaultGroups")
is:bun: m2m relation=DefaultGroups does not have base model=App with key=['\x01' '\x01'] (check join conditions)
Could somebody please give me some hint what I have to fix?
My models are roughly:
Beta Was this translation helpful? Give feedback.
All reactions