diff --git a/CHANGELOG.md b/CHANGELOG.md index 96c82b7f4..ab12292f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -#Unreleased +## Unreleased + +### Fixed - Fix bug in many-many relation detection - @ruslantalpa +- Inconsistent escaping of table names in read queries - @calebmer ## [0.3.0.2] - 2015-12-16 diff --git a/src/PostgREST/QueryBuilder.hs b/src/PostgREST/QueryBuilder.hs index d4e916631..aebcded84 100644 --- a/src/PostgREST/QueryBuilder.hs +++ b/src/PostgREST/QueryBuilder.hs @@ -271,20 +271,20 @@ requestToQuery schema (DbRead (Node (Select colSelects tbls conditions ord, (nod getQueryParts (Node n@(_, (name, Just (Relation {relType=Child,relTable=Table{tableName=table}}))) forst) (j,s) = (j,sel:s) where sel = "COALESCE((" - <> "SELECT array_to_json(array_agg(row_to_json("<>table<>"))) " - <> "FROM (" <> subquery <> ") " <> table + <> "SELECT array_to_json(array_agg(row_to_json("<>pgFmtIdent table<>"))) " + <> "FROM (" <> subquery <> ") " <> pgFmtIdent table <> "), '[]') AS " <> pgFmtIdent name where subquery = requestToQuery schema (DbRead (Node n forst)) getQueryParts (Node n@(_, (name, Just (Relation {relType=Parent,relTable=Table{tableName=table}}))) forst) (j,s) = (joi:j,sel:s) where - sel = "row_to_json(" <> table <> ".*) AS "<>pgFmtIdent name --TODO must be singular - joi = ("( " <> subquery <> " ) AS " <> table, table) + sel = "row_to_json(" <> pgFmtIdent table <> ".*) AS "<>pgFmtIdent name --TODO must be singular + joi = ("( " <> subquery <> " ) AS " <> pgFmtIdent table, table) where subquery = requestToQuery schema (DbRead (Node n forst)) getQueryParts (Node n@(_, (name, Just (Relation {relType=Many,relTable=Table{tableName=table}}))) forst) (j,s) = (j,sel:s) where sel = "COALESCE ((" - <> "SELECT array_to_json(array_agg(row_to_json("<>table<>"))) " - <> "FROM (" <> subquery <> ") " <> table + <> "SELECT array_to_json(array_agg(row_to_json("<>pgFmtIdent table<>"))) " + <> "FROM (" <> subquery <> ") " <> pgFmtIdent table <> "), '[]') AS " <> pgFmtIdent name where subquery = requestToQuery schema (DbRead (Node n forst)) --the following is just to remove the warning