3

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をとして射影する方法はありMaybe (Entity Inventory)ますか?

4

1 に答える 1