Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell - Couldn't match type ‘PersistEntityBackend record0’ with ‘SqlBackend’

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

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 get is:

• 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 that?

like image 329
Vitaly Olegovitch Avatar asked May 31 '26 11:05

Vitaly Olegovitch


1 Answers

First thing I did was to run stack ghci.

Then I run :info Actor, where Actor is the name of my PersistEntity.

Among other things, there was:

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")
like image 112
Vitaly Olegovitch Avatar answered Jun 02 '26 09:06

Vitaly Olegovitch