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

Many-to-Many Relationship with extra ID field results in a scan error #709

Closed
longchu-1209 opened this issue Nov 14, 2022 · 1 comment · Fixed by #837
Closed

Many-to-Many Relationship with extra ID field results in a scan error #709

longchu-1209 opened this issue Nov 14, 2022 · 1 comment · Fixed by #837

Comments

@longchu-1209
Copy link

Hi, I was trying to setup bun many-2-many with the below specs

type Order struct {
	ID    int64  `bun:",pk"`
	Items []Item `bun:"m2m:order_to_items,join:Order=Item"`
}

type Item struct {
	ID int64 `bun:",pk"`
}

type OrderToItem struct {
	ID      string `bun:",pk" json:"id"`
	OrderID int64  `bun:",notnull"`
	Order   *Order `bun:"rel:belongs-to,join:order_id=id"`
	ItemID  int64  `bun:",notnull"`
	Item    *Item  `bun:"rel:belongs-to,join:item_id=id"`
}

The execution would result in a scan error because both OrderToItem.ID and Order.ID columns are id. The column names collide in the mapping which leads to this:

sql: Scan error on column index 0, name "id": Scan: unable to scan type string into int64

Do you guys have any suggestion because the "extra" ID in the pivot table is inevitable to our business.
Thanks alot!

@rtalhouk
Copy link

I'm having a similar issue so I'm just +1-ing this thread. Any insight would be appreciated

calorie added a commit to calorie/bun that referenced this issue May 27, 2023
calorie added a commit to calorie/bun that referenced this issue May 27, 2023
calorie added a commit to calorie/bun that referenced this issue May 27, 2023
calorie added a commit to calorie/bun that referenced this issue May 27, 2023
calorie added a commit to calorie/bun that referenced this issue May 27, 2023
calorie added a commit to calorie/bun that referenced this issue May 28, 2023
vmihailenco pushed a commit that referenced this issue Sep 10, 2023
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 a pull request may close this issue.

2 participants