如果我们在模型文件中定义了 2 个简单对象,例如:-
Person
name Text
Age Int
Book
title Text
author Text
我们可以为 Book 定义一个应用形式:-
addBookForm = renderDivs $ Book
<$> areq textField "title" Nothing
<*> areq textField "author" Nothing
但是,如果我们想将作者从一个文本字段更改为一个人的 id,如下所示:-
Book
title Text
author PersonId
然后上面的表单将无法编译,并出现此错误:-
Couldn't match expected type `KeyBackend Database.Persist.GenericSql.Raw.SqlBackend Person' with actual type `Text'
Expected type: Field
sub0
master0
(KeyBackend Database.Persist.GenericSql.Raw.SqlBackend Person)
Actual type: Field sub0 master0 Text
In the first argument of `areq', namely `textField'
In the second argument of `(<*>)', namely
`areq textField "author" Nothing'
我们现在如何定义作者字段?我们需要使用一元形式吗?
谢谢 !