Artsicle/Blog — pull request #8 by pathouse (2014-07-04 17:34:19+00:00)
Title: User has posts

Happy fourth of July folks!

Just wanted to push up some Go stuff I was just working on because of a gotcha I hit with Gorm. Might be something that we'll want to dig in and fix with Gorm itself or it might be a problem with Go's sql library, though currently I'm 98% sure it's the former and not the latter.

got this error when attempting to set DeletedAt to null
`(sql: Scan error on column index 6: unsupported driver -> Scan pair: -> *time.Time)`

This may be a Gorm problem or a problem with the sql library within Go itself (based on some preliminary reading of Go's sql lib I'm 98% sure it's Gorm's problem).
Either way, the solution for soft deletes in Gorm apparently is setting the DeletedAt column of non-deleted objects to a time in the distant past

`STATEMENT: SELECT * FROM "posts" WHERE (deleted_at IS NULL OR deleted_at <= '0001-01-02') AND (("UserId" = $1))`

Another tricky thing is that if a sql query turns up no records, Gorm throws a RecordNotFound error. For now I've added a bool flag to the find method so we can ignore this at will but there might be a better solution.