Haskell - Could not match type 'PersistEntityBackend record0 with' SqlBackend

I am trying to get a record by id in Yesod. My code:

getEditActorR :: Handler Html
getEditActorR = do
    actorId <- runInputGet $ ireq intField "id"
    actor <- runDB $ get $ Key $ PersistInt64 (fromIntegral actorId)
    defaultLayout $ do
        $(widgetFile "actor-edit")

      

The error I am getting:

 Couldn't match type ‘PersistEntityBackend record0’
                 with ‘SqlBackend’
    arising from a use of ‘get’
  The type variable ‘record0’ is ambiguous
 In the second argument of ‘($)’, namely
    ‘get $ Key $ PersistInt64 (fromIntegral actorId)’
  In a stmt of a 'do' block:
    actor <- runDB $ get $ Key $ PersistInt64 (fromIntegral actorId)
  In the expression:
    do { actorId <- runInputGet $ ireq intField "id";
         actor <- runDB $ get $ Key $ PersistInt64 (fromIntegral actorId);
         defaultLayout $ do { (do { ... }) } }

      

How can I fix this?

+3


source to share


1 answer


The first thing I did was launch stack ghci

.

Then I run :info Actor

where Actor is the name of my PersistEntity.

Among other things, there were:



newtype instance Key Actor = ActorKey {unActorKey :: Int}

      

So I wrote:

maybeActor <- runDB $ get $ ActorKey actorId
case maybeActor of
    Just actor -> defaultLayout $ do
        $(widgetFile "actor-edit")
    Nothing -> defaultLayout $ do
        $(widgetFile "actor-new")

      

+3


source







All Articles