Fixes https://github.com/jinzhu/gorm/issues/317