Closed worm2fed closed 1 year ago
Seems like I found a solution.
query = do
individual@IndividualSchema{..} <- Sql.each individualSchema
interests <- Sql.many $ getInterestByIndividualPkQ isIndividualPk
whenJust mq $ \q ->
Sql.where_ . Sql.foldOr $
(q `Sql.iLikeCast` isName)
:| [ q `Sql.iLikeCast` isMission
, q `Sql.iLikeCast` isPhone
, q `Sql.iLikeCast` (Interest.isName Sql.$* interests)
]
pure (individual, interests)
I had to make a projection $*
Hello! Hope you can help me..
I have this query
And it works good. There is some individuals and they can have interests (via many-2-many). In this example I just filter by individual's fields.
But now I want to include results filtered by interests as well. So, for example I have an individual with interest "Bonsai", and when
mq = Just "Bonsai"
- I want to filter by it, similar as by other fields –... Sql.||. (q
Sql.iLikeInterest.isName interests)
The best solution I was able to find is this (which is works partially):
Problem with it that it excludes individuals without any interest (even when
mq = Nothing
) and duplicates entries (I guess - each per interest). The second problem can be solved withdistinct
, but not first one.Another solution I've tried is to make to queries - one from the example at the beginning and second one similar to second example, but with proper usage of
aggregate
, and at the top -union
- and this is works, but it's so ugly...Seems like the main problem is that I do not understand how to work with
ListTable
.Thank you!