从一个人为config/models
的脚手架网站:
Inventory
name Text
description Text
Container
name Text
ContainerSlot
container ContainerId
item InventoryId Maybe
现在,使用 Esqueleto,我想用来LeftOuterJoin
获取容器中的插槽,如果尚未分配实际库存,则实际库存为空。
selectContainerSlots containerKey = do
stuff <- select $ from $ \(cs `LeftOuterJoin` i) -> do
on $ cs ^. ContainerSlotItem ==. just (i ^. InventoryId)
where_ $ cs ^. ContainerSlotContainer ==. val containerKey
return (cs, i)
return $ uncurry buildStuff <$> stuff
buildStuff
由于联接的“外部”性质,我希望需要以下签名:
buildStuff :: Entity ContainerSlot -> Maybe (Entity Inventory) -> Result
但发现它需要以下内容:
buildStuff :: Entity ContainerSlot -> Entity Inventory -> Result
Inventory
当(可预测地)字段填充有NULL
值时,这会导致运行时失败。
PersistMarshalError "field id: int64 Expected Integer, received: PersistNull"
有没有办法将Entity Inventory
as投影到Maybe (Entity Inventory)
?