Hashing by Persistent's Entity key?
haskell, yesod
Solution
Does it have to be a `HashMap`? `Data.Map` only needs `Ord`. The `Hashable` class is a bit dodgy and could use a fix-up anyway.
Unless you know what you're doing and understand the flaws in the hashing behavior of `Hashable` you should never use `HashMap` where a `Data.Map` would do.
This has the side effect of avoiding unnecessary orphan instances. (More things are Ord than Hashable)
Problem
I'm trying to build a `Data.HashMap` structure by grouping multiple Persistent entities by their foreign key field. E.g. say I have these two entities (straight out of the Yesod book) ``` Person name String age Int Maybe deriving Show BlogPost title String authorId PersonId deriving Show ``` and I want a: ``` HashMap PersonId [BlogPost] ``` The challenge here is that PersonId does not directly implement `Hashable` (from Data.Hashable) and additionally it's abstracted depending on which DB you're using (Postgres in my case). I suppose (just a wild beginner guess) I could implement Hashable for PersonId myself by doing `fromPersistValue` and a `read` into an Int64, for which there's a Hashable implementation already, but I imagine there might be a less convoluted way of achieving that. Any suggestions?