Yesod persistence error

I am trying to find persistence in a Yesod application. My model file contains

Job issuer MemberId addDate UTCTime lastDate UTCTime title Text description Text deriving Show Read 

And my handler:

 getProfileR :: Handler RepHtml getProfileR = do jobs <- runDB $ selectList [] [Desc JobAddDate] defaultLayout $ do setTitle "title" $(widgetFile "profile") 

In profile.hamlet I go through objects

 $forall Job issuer addDate lastDate title description <- jobs <p>#{issuer} 

However, I get the following error

 Handler/Profile.hs:36:18: Couldn't match type `Entity' with `JobGeneric' In the return type of a call of `selectList' In the second argument of `($)', namely `selectList [] [Desc JobAddDate]' In a stmt of a 'do' block: jobs <- runDB $ selectList [] [Desc JobAddDate] Handler/Profile.hs:36:18: Kind incompatibility when matching types: t0 :: (* -> *) -> * -> * JobGeneric Database.Persist.GenericSql.Raw.SqlPersist :: * In the return type of a call of `selectList' In the second argument of `($)', namely `selectList [] [Desc JobAddDate]' In a stmt of a 'do' block: jobs <- runDB $ selectList [] [Desc JobAddDate] Build failure, pausing... 

If line 36 is runDB line.

Being new to Haskell, I can't figure out what happened. I follow the Book of Yesod. They unfortunately avoid the Forest Site, so I can’t completely simulate their code.

+4
source share
1 answer

selectList does not return [Job] , it is actually [Entity Job] , which contains both Job and its Key *

There are several ways to reorganize this to handle it:

 $forall Entity jobId job <- jobs <p>#{jobIssuer job} 

In your template.

Alternatively, you can use map entityVal at any time to enable [Entity Job] -> [Job] if you prefer to work with this.

* Entity and Key types are actually a little more complicated, but it’s easier for me to think of them that way. Please read the documents if you are interested.

+4
source

All Articles