articles icon indicating copy to clipboard operation
articles copied to clipboard

Gorm Gotchas

Open depado opened this issue 7 years ago • 4 comments

This is the comment issue for the Gorm Gotchas article.

depado avatar Mar 19 '18 22:03 depado

Hey, thanks for the article!

I was wondering how are you supposed to use Article and Tag if you declare them inside the migration, do you re-declare them outside of the migration or what is your approach?

shackra avatar Sep 22 '18 06:09 shackra

@shackra Hey, thanks for the article!

I was wondering how are you supposed to use Article and Tag if you declare them inside the migration, do you re-declare them outside of the migration or what is your approach?

Hey :) Thanks for your feedback. You declare them both in your migration and in your model. This way, your migrations are not tied with your model.

depado avatar Sep 24 '18 08:09 depado

Not sure if it has changed with gorm version, but this,

MetaDataB postgres.Jsonb `gorm:"type:jsonb;"

seems to not work anymore.

MetaDataB json.RawMessage `gorm:"type:jsonb;"`

works

getmetorajesh avatar Mar 24 '19 10:03 getmetorajesh

Hey. I'll give that a try when I'll have time, but at the time of writing this did work. I'm surprised that json.RawMessage would work. Under the hood, postgres.Jsonb is effectively a json.RawMessage but it also implements the sql.Scanner and driver.Valuer interfaces so that gorm can effectively use this type as you can see in the source code of Gorm Thanks a lot for your feedback on my post!

depado avatar Mar 25 '19 09:03 depado