This query works. The difference between the query I had posted in my question and this one is really the ?.
I thought I tried that variation but perhaps missed the obvious. I am still unclear when we will use . I noticed I also get a working query if removed ?.
though. E.just
and used ?.
for the CatTable Entity (c)
.
myQuery :: (PersistQuery (SqlPersistT m), MonadLogger m , MonadResourceBase m) =>
SqlPersistT m [(E.Value (Maybe Text), E.Value (Maybe Double))]
myQuery = do
E.select $ E.from $ \(t `E.LeftOuterJoin` c) -> do
E.on (t E.^. MyTableCategory E.==. E.just (c E.^. CatTableId))
E.groupBy $ E.just (c E.^. CatTableName)
let sum' = E.sum_ (t E.^. MyTableAmount)
E.orderBy [E.desc sum']
return (E.just (c E.^. CatTableName) ,sum')