尝试以消化函子形式解析内置类型没有问题,例如,我有一个引用国家 ID(关键国家类型)的客户端类型(由持久库生成):
Client
:: String
-> String
-> String
-> Database.Persist.Class.Key Country
-> Maybe Int
-> Client
然后我定义了一个 clientForm 值:
clientForm :: Monad m => Form String m Client
clientForm = Client <$> "firstName" .: string Nothing
<*> "lastName" .: string Nothing
<*> "address" .: string Nothing
<*> "country" .: stringRead "Cannot parse country" Nothing
<*> "age" .: optionalStringRead "Cannot parse age" Nothing
奇怪的是,clientForm 在提交(POST)时,无法解析 country id 字段。
使用“stringRead”解析“Key Country”类型(可以从“toSqlKey int64”中获取)有错吗?