データベース フィールド (テキスト) を抽出し、ハンドラーから別の関数に引数として渡したいと思います。ただし、タイプ エラーが発生します。完全に作成された例なので、少し不自然に感じるかもしれませんが、私が抱えている問題を説明する必要があります.
Person
name Text
Car
personId PersonId
name Text
type Text
Car エンティティを取得してから、対応する Person を見つけたいと思います。彼の名前を取得し、それを引数として渡します。何かのようなもの:
data MyD = MyD { input1 :: Int}
entryForm :: Text -> Form MyD -- Update: Removed the incorrect extra parameter
entryForm n1 = renderDivs $ MyD
<$> areq intField n1 Nothing
私の get ハンドラーは次のようになります。
getInputR :: CarId -> Handler Html
getInputR carId = do
car <- runDB $ get404 carId
pid <- carPersonId car
name <- getPName pid
(widget, enctype) <- generateFormPost $ entryForm name
defaultLayout $ do
$(widgetFile "my_template")
where
getPName pid = do
person <- runDB $ get404 pid
personName person
次のようなエラーが表示されます。
Couldn't match expected type `HandlerT App IO t0'
with actual type `KeyBackend
persistent-1.2.1:Database.Persist.Sql.Types.SqlBackend Person'
In the return type of a call of `carPersonId'
In a stmt of a 'do' block: pid <- carPersonId car
私は何を間違っていますか?
ありがとう!