diff --git a/src/Database/Esqueleto/Utils.hs b/src/Database/Esqueleto/Utils.hs index 701ce9616..f3aec73aa 100644 --- a/src/Database/Esqueleto/Utils.hs +++ b/src/Database/Esqueleto/Utils.hs @@ -7,7 +7,6 @@ module Database.Esqueleto.Utils , SqlIn(..) , mkExactFilter, mkContainsFilter , anyFilter - , inList ) where import ClassyPrelude.Yesod hiding (isInfixOf, any, all) @@ -100,12 +99,4 @@ anyFilter :: (Foldable f) => f (t -> Set.Set Text-> E.SqlExpr (E.Value Bool)) -> t -> Set.Set Text-> E.SqlExpr (E.Value Bool) anyFilter fltrs needle criterias = F.foldr aux false fltrs where - aux fltr acc = fltr needle criterias E.||. acc - --- | Convenience for Sorting by a Column being element of a certain List --- Does not work, may produce esqueleto error --- `unsafeSqlBinOp: non-id/composite keys not expected here` somehow -inList :: (PersistField typ, PersistEntity val) - => EntityField val typ -> [typ] -> E.SqlExpr (Entity val) -> E.SqlExpr (E.Value Bool) -inList _column [] = const $ E.val True -inList column l = \row -> row E.^. column `E.in_` E.valList l + aux fltr acc = fltr needle criterias E.||. acc \ No newline at end of file diff --git a/src/Handler/Admin.hs b/src/Handler/Admin.hs index 2322fb0a9..2ee38518b 100644 --- a/src/Handler/Admin.hs +++ b/src/Handler/Admin.hs @@ -404,8 +404,9 @@ postAdminFeaturesR = do ] dbtSorting = Map.fromList [ ("key" , SortColumn (E.^. StudyTermsKey)) - , ("isnew" , SortColumn (StudyTermsKey `E.inList` (unStudyTermsKey <$> Set.toList newKeys))) - , ("isbad" , SortColumn (StudyTermsKey `E.inList` (unStudyTermsKey <$> Set.toList badKeys))) + , ("isnew" , SortColumn (\studyTerm -> studyTerm E.^. StudyTermsKey `E.in_` E.valList (unStudyTermsKey <$> Set.toList newKeys))) + -- Remember: sorting with E.in_ by StudyTermsId instead will produce esqueleto-error "unsafeSqlBinOp: non-id/composite keys not expected here" + , ("isbad" , SortColumn (\studyTerm -> studyTerm E.^. StudyTermsKey `E.in_` E.valList (unStudyTermsKey <$> Set.toList badKeys))) , ("name" , SortColumn (E.^. StudyTermsName)) , ("short" , SortColumn (E.^. StudyTermsShorthand)) ]