Don't error when attempting to sort on an object field (#4806)

* add failing test to demonstrate that you can't sort on a
field in an object.

* Only validate the base of the field name.

* fix test name

* Only test sort for mongo.

* pg order by nested object

* level 2 test

* Factor out operation to get a field's base name.  Add comment.

* tweak comment wording so it wont make my grammar teacher angry.
This commit is contained in:
Arthur Cinader
2018-06-07 15:47:18 -07:00
committed by Florent Vilmart
parent cf3a872e67
commit e06471603f
3 changed files with 101 additions and 5 deletions

View File

@@ -1397,11 +1397,12 @@ export class PostgresStorageAdapter implements StorageAdapter {
if (sort) {
const sortCopy: any = sort;
const sorting = Object.keys(sort).map((key) => {
const transformKey = transformDotFieldToComponents(key).join('->');
// Using $idx pattern gives: non-integer constant in ORDER BY
if (sortCopy[key] === 1) {
return `"${key}" ASC`;
return `${transformKey} ASC`;
}
return `"${key}" DESC`;
return `${transformKey} DESC`;
}).join();
sortPattern = sort !== undefined && Object.keys(sort).length > 0 ? `ORDER BY ${sorting}` : '';
}