Should Gorm write one-to-many relationship, has many and belongs to both set or just write one side?

do you want to set both, has many and belongs to for Gorm"s one-to-many relationships or just write on one side?
it seems that the official website only writes on one side, not on both sides. http://gorm.io/zh_CN/docs/has.

clipboard.png

Jan.29,2022

personally, I don't think it's necessary to use these, which will make the whole look messy, so just make a normal query.


belongs to is not a concept. You use belongs to to associate two struct,. You insert a table into the database as an operation. You can see it over and over again, or you don't need belongs to

to understand it this way.
Menu