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

sharding key or id required, and use operator = #61

Closed
Tk4s opened this issue Aug 11, 2022 · 3 comments
Closed

sharding key or id required, and use operator = #61

Tk4s opened this issue Aug 11, 2022 · 3 comments
Assignees

Comments

@Tk4s
Copy link

Tk4s commented Aug 11, 2022

GORM Playground Link

go-gorm/playground#1

Description

When i use preload on sharding table, the return "msg sharding key or id required, and use operator ="

type A struct {
ID string
BS []B
}

type B struct {
ID string
AID string
}

var aModel A

db.Model(&A{}).Preload("B").Find(&aModel)

@huacnlee
Copy link
Collaborator

This is not a bug.

Sharding must have a shard key, and you must present the shard key in every query conditions. If we not providing that, the Sharding implementation can not know which sub table to query.

@Tk4s
Copy link
Author

Tk4s commented Aug 12, 2022

Hi, but i see the sql has shardingkey , like this:
SELECT * FROM scan WHERE scan.sys_group_space_app_id = '62f3723a238b2add3cdbed71'

the sys_group_space_app_id is table scan shardingKey.

And i find another problem.
1: cannot use hook
2: cannot use Clauses

This will cause GORM to insert data into the primary table instead of the sub-table

@hyperphoton
Copy link
Collaborator

Your primary table is A but there is no sharding key on A.

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

No branches or pull requests

4 participants