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

Dynamic struct autoIncrement ID problem in Create error '@id' field does not exist, 动态结构体Create 时报错’@id’字段不存在 #7259

Closed
sin3degrees opened this issue Oct 31, 2024 · 1 comment
Assignees
Labels

Comments

@sin3degrees
Copy link

Dynamic struct autoIncrement ID problem in Create error '@id' field does not exist, statically compiled struct does not have this problem. As a temporary solution, the gorm tag is set autoIncrement:false, generates the ID with snowflake, and ensures that the corresponding database table ID is not set to increment.
I use the goja library to call the go function, and js class can only turn the dynamic structure, in order to let js use gorm, using the specified table name of the dynamic structure scheme, playground is not convenient to repeat the problem, which the call process is relatively complex.
动态结构体自增 ID 在 Create 时报错’@id’字段不存在的问题,静态编译的结构体没这个问题。临时解决方案,gorm 标签设置 autoIncrement:false,用 snowflake 生成 ID,并且保证对应的数据库表的 ID 不设置自增。
本人使用 goja 库调用 go 函数,而 js类只能转动态结构体,为了让 js 使用 gorm,采用了指定表名的动态结构体方案,playgroud 不方便复现问题,其中的调用过程相对复杂。

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Oct 31, 2024
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 30, 2024
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

2 participants