From a contrived config/models
in a scaffolded site:
Inventory
name Text
description Text
Container
name Text
ContainerSlot
container ContainerId
item InventoryId Maybe
Now, using Esqueleto, I want to use LeftOuterJoin
to get the slots in a container, with the actual inventory empty if it has not been assigned.
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
I would expect buildStuff
to need the following signature due to the "outer" nature of the join:
buildStuff :: Entity ContainerSlot -> Maybe (Entity Inventory) -> Result
but find that it needs the following:
buildStuff :: Entity ContainerSlot -> Entity Inventory -> Result
Which causes runtime failures when (predictably) the the Inventory
fields are filled with NULL
values.
PersistMarshalError "field id: int64 Expected Integer, received: PersistNull"
Is there a way to project the Entity Inventory
as an Maybe (Entity Inventory)
?