From 0c694e92a53bb5cd57e557b232ba06189dad5044 Mon Sep 17 00:00:00 2001 From: Felipe Lessa Date: Wed, 5 Sep 2012 16:53:55 -0300 Subject: [PATCH] On collectOnClauses, match from clauses in the correct order. Previously it tried matching on the right branch just after matching on the current node, which means that on the default right fixity everything was reversed. Note: SQLite didn't give any error messages for this bug! --- src/Database/Esqueleto/Internal/Sql.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Database/Esqueleto/Internal/Sql.hs b/src/Database/Esqueleto/Internal/Sql.hs index a72e873..9c8a75c 100644 --- a/src/Database/Esqueleto/Internal/Sql.hs +++ b/src/Database/Esqueleto/Internal/Sql.hs @@ -85,11 +85,14 @@ collectOnClauses = go [] Nothing -> (f:) <$> findMatching acc expr findMatching [] expr = Left expr - tryMatch expr (FromJoin l k r Nothing) = - return (FromJoin l k r (Just expr)) - tryMatch expr (FromJoin l k r j@(Just _)) = - ((\r' -> FromJoin l k r' j) <$> tryMatch expr r) `mplus` - ((\l' -> FromJoin l' k r j) <$> tryMatch expr l) + tryMatch expr (FromJoin l k r onClause) = + matchR `mplus` matchC `mplus` matchL -- right to left + where + matchR = (\r' -> FromJoin l k r' onClause) <$> tryMatch expr r + matchL = (\l' -> FromJoin l' k r onClause) <$> tryMatch expr l + matchC = case onClause of + Nothing -> return (FromJoin l k r (Just expr)) + Just _ -> mzero tryMatch _ _ = mzero