Depado / articles

Articles hosted on my blog
https://blog.depado.eu
MIT License
29 stars 13 forks source link

Gorm Gotchas #20

Open Depado opened 6 years ago

Depado commented 6 years ago

This is the comment issue for the Gorm Gotchas article.

shackra commented 5 years ago

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?

Depado commented 5 years ago

@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.

getmetorajesh commented 5 years ago

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

Depado commented 5 years ago

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!