這是我的架構:
Posts:
id
roomsId
Rooms:
id
RoomEvents:
id
roomId
userId
created_at
我正在寫的查詢是:
action MyAction { .. } = do
.
.
roomEvent <- query @RoomEvent
|> filterWhere (#roomId, roomId)
|> orderBy #createdAt
|> fetchOneOrNothing
>>= fetchRelated #userId
但這會引發以下錯誤:
Web/Controller/Posts.hs:150:21: error:
? Could not deduce (FromRow fetchModel0)
arising from a use of ‘fetchRelated’
from the context: (?context::ControllerContext,
?modelContext::ModelContext, ?theAction::PostsController)
bound by the type signature for:
action :: (?context::ControllerContext,
?modelContext::ModelContext, ?theAction::PostsController) =>
PostsController -> IO ()
at Web/Controller/Posts.hs:57:5-10
The type variable ‘fetchModel0’ is ambiguous
The type variable ‘fetchModel0’ is ambiguous
These potential instances exist:
instance Database.PostgreSQL.Simple.FromField.FromField a =>
FromRow (Only a)
-- Defined in ‘Database.PostgreSQL.Simple.FromRow’
instance FromRow Activity
-- Defined at build/Generated/Types.hs:412:10
instance FromRow ActivityPostFile
-- Defined at build/Generated/Types.hs:802:10
...plus 64 others
...plus one instance involving out-of-scope types
(use -fprint-potential-instances to see them all)
? In the second argument of ‘(>>=)’, namely ‘fetchRelated #userId’
這是否意味著從其他表生成的實體會干擾此查詢?我已經嘗試使用fetchRelatedOrNothing和maybeFetchRelatedOrNothing太。
更新:我在我的視圖中放置了錯誤的型別,這導致型別系統推斷出錯誤的型別。更改視圖中的型別,立即解決了問題。
uj5u.com熱心網友回復:
使用maybeFetchRelatedOrNothing應該在這里作業:
roomEvent <- query @RoomEvent
|> filterWhere (#roomId, roomId)
|> orderBy #createdAt
|> fetchOneOrNothing
>>= maybeFetchRelatedOrNothing #userId
您嘗試此操作時出現了什么錯誤?
還|> orderBy #createdAt需要表中的一created_at列room_events,但未將其列為架構的一部分。也許這也會影響這個問題?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/363880.html
上一篇:如何針對已編譯的包運行GHCi?
