使用Yesod和Persistent键入不匹配

时间:2014-04-30 02:57:25

标签: haskell yesod persistent

我正在尝试使用Yesod应用程序进行持久性查询:

userDetails :: UserId -> HandlerT app IO (Maybe UserDetail)
userDetails uid = do
  profile <- getBy $ UniqueUser uid
  return $ undefined -- the rest of this type checks

我在getBy行上遇到类型错误:

Couldn't match type `PersistMonadBackend (HandlerT App IO)'
      with `persistent-1.3.0.6:Database.Persist.Sql.Types.SqlBackend'
Expected type: PersistMonadBackend (HandlerT App IO)
  Actual type: PersistEntityBackend Profile

所以,检查ghci中的类型:

:t getBy (UniqueUser undefined)
   getBy (UniqueUser undefined)
     :: ( PersistUnique m,
        , PersistMonadBackend m ~ persistent-1.3.0.6:Database.Persist.Sql.Types.SqlBackend
        ) => m (Data.Maybe.Maybe (Entity Profile))

但事实是,我将Profile定义为:

Profile
    name  Text
    email Text
    user  UserId
    UniqueUser  user
    UniqueEmail email

在我的'config / model'文件中。发生了什么,我该如何解决?

1 个答案:

答案 0 :(得分:3)

您需要在持久调用周围使用runDB。