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

V2.7 cannot use ORM JSON storage #3560

Closed
Gallery2000 opened this issue May 5, 2024 · 5 comments
Closed

V2.7 cannot use ORM JSON storage #3560

Gallery2000 opened this issue May 5, 2024 · 5 comments
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@Gallery2000
Copy link

Gallery2000 commented May 5, 2024

Go version

1.21

GoFrame version

2.7

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

评论区已经有人反馈了,所有的json都字段都被解析成了空字符插入到数据库。当我把gf版本降到2.64执行gf gen dao后一切就正常了。
image
image

What did you see happen?

help

What did you expect to see?

help

@Gallery2000 Gallery2000 added the bug It is confirmed a bug, but don't worry, we'll handle it. label May 5, 2024
@Issues-translate-bot Issues-translate-bot changed the title V2.7无法使用ORM JSON存储 V2.7 cannot use ORM JSON storage May 5, 2024
@wln32
Copy link
Member

wln32 commented May 5, 2024

我在我的机器上试了pgsql没问题,另这个和mysql没有关系,只要数据库支持json类型的字段就可以

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I tried pgsql on my machine and there was no problem. This has nothing to do with mysql, as long as the database supports json type fields.

@leavky
Copy link

leavky commented May 27, 2024

社区的这个问题是我写的,看到说是2.64是正常的,我降级后将生成的文件和2.7生成的文件对比了下,发现了问题。
2.6.4生成的:
image
2.7 以及 2.7.1 生成的:
image
通过对比发现2.7 生成的多了orm标签
现在有两个解决办法:

  1. 修改生成的文件,将orm标签删除
  2. 不修改生成的文件,在自己上一级结构体中写上 orm 标签。
    image

希望可以改下,官方工具不生成这个orm标签

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I wrote this question in the community. I saw that it was normal for 2.64. After downgrading, I compared the generated files with those generated by 2.7 and found the problem.
Generated by 2.6.4:
image
2.7 and 2.7.1 generated:
image
Through comparison, it was found that 2.7 generated more ORM tags.
There are two solutions now:

  1. Modify the generated file and delete the orm tag
  2. Do not modify the generated file, but write the orm tag in the upper-level structure.
    image

I hope it can be changed. The official tool does not generate this ORM tag.

@Gallery2000
Copy link
Author

Gallery2000 commented Jun 2, 2024

对不起,我更正一下,如果插入的字段为元组类型并且len为0 ,则会提示错误:
Error: Error 3140 (22032): Invalid JSON text: "The document is empty." at position 0 in value for column 'xxx.xxx'.

dao.Message.Ctx(ctx).Data(model.MessageItem{
        Message:&entity.Message{
              ...
        },
        Embeds: make([]MessageEmbed, 0),
}).Insert()

dao.Message.Ctx(ctx).Data(message).FieldsEx(fieldsEx).Insert()

目前是用FieldsEx解决空值无法被映射为json的问题,但感觉还是老版本自动映射更加好用。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.
Projects
None yet
Development

No branches or pull requests

4 participants