diff --git a/src/clauses.js b/src/clauses.js index 674f393a..fe5b1da3 100644 --- a/src/clauses.js +++ b/src/clauses.js @@ -973,12 +973,21 @@ let clauses = { sk, pk, ); + + const accessPattern = + entity.model.translations.indexes.fromIndexToAccessPattern[ + state.query.index + ]; + + if (!entity.model.indexes[accessPattern].sk.isFieldRef) { + state.filterProperties(FilterOperationNames.lte, endingSk.composites); + } + return state .setType(QueryTypes.and) .setSK(endingSk.composites) .setType(QueryTypes.between) - .setSK(startingSk.composites) - .filterProperties(FilterOperationNames.lte, endingSk.composites); + .setSK(startingSk.composites); } catch (err) { state.setError(err); return state; @@ -1019,9 +1028,14 @@ let clauses = { pk, ); state.setSK(composites); - state.filterProperties(FilterOperationNames.gt, { - ...composites, - }); + const accessPattern = + entity.model.translations.indexes.fromIndexToAccessPattern[ + state.query.index + ]; + + if (!entity.model.indexes[accessPattern].sk.isFieldRef) { + state.filterProperties(FilterOperationNames.lte, composites); + } }); } catch (err) { state.setError(err); @@ -1086,9 +1100,13 @@ let clauses = { pk, ); state.setSK(composites); - state.filterProperties(FilterOperationNames.lte, { - ...composites, - }); + const accessPattern = + entity.model.translations.indexes.fromIndexToAccessPattern[ + state.query.index + ]; + if (!entity.model.indexes[accessPattern].sk.isFieldRef) { + state.filterProperties(FilterOperationNames.lte, composites); + } }); } catch (err) { state.setError(err); diff --git a/src/entity.js b/src/entity.js index e7bcb48c..beddd602 100644 --- a/src/entity.js +++ b/src/entity.js @@ -4409,6 +4409,7 @@ class Entity { getClient: () => this.client, isRoot: true, }); + let filters = this._normalizeFilters(model.filters); // todo: consider a rename let prefixes = this._normalizeKeyFixings({ @@ -4445,6 +4446,12 @@ class Entity { labels, attributes, ); + for (let attributeName in schema.attributes) { + const { field } = schema.attributes[attributeName]; + if (indexes[accessPattern][keyType].field === field) { + indexes[accessPattern][keyType].isFieldRef = true; + } + } } }