Yesod持久性类型错误 [英] Yesod persistent type error
问题描述
工作
issuer MemberId
addDate UTCTime
lastDate UTCTime
title文本
描述文本
派生显示读取
和我的Handler:
getProfileR :: Handler RepHtml
getProfileR = do
jobs< - runDB $ selectList [] [Desc JobAddDate]
defaultLayout $ do
setTitletitle
$(widgetFileprofile)
在profile.hamlet中,我循环对象
$ forall作业发布者addDate lastDate标题说明< - jobs
< p>#{issuer}
但是,我得到以下错误
Handler / Profile.hs:36:18:
无法使用JobGeneric匹配类型实体
在`selectList'调用的返回类型中
在`($)'的第二个参数中,即
`selectList [] [Desc JobAddDate]'
在'do'块的结构:
jobs< - runDB $ selectList [] [Desc JobAddDate]
Handler / Profile.hs:36:18:
种类不兼容匹配类型:
t0 ::(* - > *) - > * - > *
JobGeneric Database.Persist.GenericSql.Raw.SqlPersist :: *
在`selectList'调用的返回类型中
在`($)'的第二个参数中,即
`selectList [] [Desc JobAddDate]'
在'do'块的标记中:
作业< - runDB $ selectList [] [Desc JobAddDate]
构建失败,暂停...
第36行是runDB行。
作为Haskell的新手,我无法弄清楚什么是错的。我遵循Yesod Book。他们不幸的是避免了Scaffolded站点,所以我不能完全模仿他们的代码。
selectList 不会返回 [作业]
,它实际上是 [实体作业]
,它包含 Job 及其键
*
方法来重构这个来处理它,其中一个是:
$ forall实体jobId工作< - 工作
< ; p>#{jobIssuer job}
在您的模板中。
另外,您可以在任意点使用 map entityVal
来打开 [Entity Job] - > [作业]
如果你喜欢使用它。
实体
>和 Key
类型实际上有点复杂,但我觉得用这种方式考虑它们会更容易。如果您有兴趣,请阅读文档。
I am trying out persistent in a Yesod application. My model file contains
Job
issuer MemberId
addDate UTCTime
lastDate UTCTime
title Text
description Text
deriving Show Read
And my Handler:
getProfileR :: Handler RepHtml
getProfileR = do
jobs <- runDB $ selectList [] [Desc JobAddDate]
defaultLayout $ do
setTitle "title"
$(widgetFile "profile")
In profile.hamlet I loop trough the objects
$forall Job issuer addDate lastDate title description <- jobs
<p>#{issuer}
However, I get the following error
Handler/Profile.hs:36:18:
Couldn't match type `Entity' with `JobGeneric'
In the return type of a call of `selectList'
In the second argument of `($)', namely
`selectList [] [Desc JobAddDate]'
In a stmt of a 'do' block:
jobs <- runDB $ selectList [] [Desc JobAddDate]
Handler/Profile.hs:36:18:
Kind incompatibility when matching types:
t0 :: (* -> *) -> * -> *
JobGeneric Database.Persist.GenericSql.Raw.SqlPersist :: *
In the return type of a call of `selectList'
In the second argument of `($)', namely
`selectList [] [Desc JobAddDate]'
In a stmt of a 'do' block:
jobs <- runDB $ selectList [] [Desc JobAddDate]
Build failure, pausing...
Where line 36 is the runDB line.
Being new to Haskell, I can't figure out whats wrong. I am following the Yesod Book. They are unfortunately avoiding the Scaffolded Site so I can't completely mimic their code.
解决方案 selectList
does not return [Job]
, it's actually [Entity Job]
which contains both the Job
and its Key
*
There are a number of ways to refactor this to handle it, one would be:
$forall Entity jobId job <- jobs
<p>#{jobIssuer job}
In your template.
Alternatively, you can use map entityVal
at any point to turn [Entity Job] -> [Job]
if you'd prefer to work with that.
*The Entity
and Key
types are actually a bit more complex, but I find it's easier to think about them this way. Please read the docs if you're interested.
这篇关于Yesod持久性类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!