我正在用Yesod開發我的第一個應用程序,並且我正在創建一些CRUD API。Yesod - 帶外鍵的表格
我有一個模型,看起來像
User json
...
Activity json
userId UserId
...
其中userId
是一個外鍵。
我需要創建一個端點才能創建一個新的活動,並且客戶端需要能夠指定userId
。
要做到這一點,我使用像
postCreateActivityR :: Hadler Value
postCreateActivityR = do
activity <- runInputPost $ Activity
<$> ...
<*> ireq textField "userId"
...
否則,形式我得到像下面這樣的錯誤:
Couldn't match type ‘Text’ with ‘Key User’ expected type: FormInput (HandlerT App IO) (Key User)
有沒有辦法解決這個問題的標準方式?
我不知道yesod的任何內容,但我會嘗試使用像http://hackage.haskell.org/package/yesod-form-1.4.15/docs/Yesod-Form-Fields.html#g中的'optionsPersistKey'這樣的機會: 4 –