gogf / gf

GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.
https://goframe.org
MIT License
11.8k stars 1.61k forks source link

V2.7 cannot use ORM JSON storage #3560

Closed Gallery2000 closed 6 months ago

Gallery2000 commented 7 months ago

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

wln32 commented 7 months ago

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

Issues-translate-bot commented 7 months ago

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 commented 6 months ago

社区的这个问题是我写的,看到说是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 commented 6 months ago

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 commented 6 months ago

对不起,我更正一下,如果插入的字段为元组类型并且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的问题,但感觉还是老版本自动映射更加好用。