Closed felixSchl closed 7 years ago
I found a somewhat nasty way around it:
-- Must use this qualified lookup, else will get:
-- * Couldn't match type ‘BaseBackend backend’ with ‘SqlBackend'
import qualified Database.Esqueleto.Internal.Sql as EIS
-- ...
E.case_
[ E.when_ (p E.^. ProductKind E.==. (E.val $ BookProductType))
-- Force Haskell to accept the underlying value as the required return Value.
-- Not very safe, but at least the function clearly indicates that.
E.then_ $ EIS.veryUnsafeCoerceSqlExprValue $ mBook E.?. BookProductId
]
(E.else_ E.nothing)
-- ...
Given a query that will run in an
SqlBackend
environment, is it possible to cast, sayproduct ^. ProductId
to anSqlExpr
ofValue Int64
? My initial approach tofmap
over bothValue a
andSqlExpr
but had to find out it could not deduce aFunctor SqlExpr
.For example, this does not work:
as it causes:
The use case here is to be able to return a list of primary keys which may come from different tables. My models look similar to:
Is this possible at all or am I doing things completely wrong?