我正在尝试通过 Yesod 中的 id 获取记录。我的代码是:
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
.
然后我跑:info Actor
,其中 Actor 是我的 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")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)