Haskell - 无法将类型“PersistEntityBackend record0"与“SqlBackend"匹配 [英] Haskell - Couldn't match type ‘PersistEntityBackend record0’ with ‘SqlBackend’
本文介绍了Haskell - 无法将类型“PersistEntityBackend record0"与“SqlBackend"匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过 Yesod 中的 id 获取记录.我的代码是:
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")
我得到的错误是:
• 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 { ... }) } }
我该如何解决?
推荐答案
我做的第一件事是运行 stack ghci
.
First thing I did was to run stack ghci
.
然后我运行 :info Actor
,其中 Actor 是我的 PersistEntity 的名称.
Then I run :info Actor
, where Actor is the name of my PersistEntity.
除此之外,还有:
newtype instance Key Actor = ActorKey {unActorKey :: Int}
所以我写道:
maybeActor <- runDB $ get $ ActorKey actorId
case maybeActor of
Just actor -> defaultLayout $ do
$(widgetFile "actor-edit")
Nothing -> defaultLayout $ do
$(widgetFile "actor-new")
这篇关于Haskell - 无法将类型“PersistEntityBackend record0"与“SqlBackend"匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文