2017-04-01 5 views
3

J'essaie d'obtenir un enregistrement par identifiant dans Yesod. Mon code est:Haskell - Impossible de trouver le type 'PersistEntityBackend record0' avec 'SqlBackend'

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

L'erreur que je reçois est:

• 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 { ... }) } } 

Comment puis-je résoudre ce problème?

Répondre

3

La première chose que j'ai faite était de lancer stack ghci.

Ensuite, je cours :info Actor, où l'acteur est le nom de mon PersistEntity.

Entre autres, il y avait:

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

J'écrit:

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