Gorp テーブル名とgorp.go

テーブル名は単数形

が、面倒がすくない。

  • Rails上がりのわしには、ちとつらい
  • 複数形でも勿論大丈夫だが、gorp.goにて通知する必要あり

gorp.go

func InitDB() {
	db.Init()
	Dbm = &gorp.DbMap{Db: db.Db, Dialect: gorp.PostgresDialect{}}

	Dbm.AddTable(models.Hotel{}).SetKeys(true, "Id")
      
        // add a table, setting the table name to 'posts' and
        // specifying that the Id property is an auto incrementing PK
        Dbm.AddTableWithName(models.Post{}, "posts").SetKeys(true, "Id")

Primary Key を通知してやらないと、Updateが上手くかかりまぬ。


参考1 https://github.com/coopernurse/gorp
参考2 http://mattn.kaoriya.net/software/lang/go/20120914222828.htm