Reputation: 2002
Dog
name Text
race Text
getAllDogsR :: Handler Html
getAllDogsR = do
Dogs<- runDB $ selectList [] [Asc DogName]
defaultLayout
[whamlet|
<ul>
$forall Entity dogid dog <- Dogs
<li>
#{show $ unKey (dogid)}
|]
When I run this code I will get a list of all dog keys that are in my database
like this:
but what I actually want is to show the pure value of the key
like this:
My question is how can I achieve this.
Upvotes: 5
Views: 554
Reputation: 1290
You need to extract the key out of a KeyBackend
first, like so:
extractKey :: KeyBackend backend entity -> String
extractKey = extractKey' . unKey
where extractKey' (PersistInt64 k) = show k
extractKey' _ = ""
You should now be able to do
#{extractKey dogid}
Upvotes: 2