From b0f469c9a74c8ec73e578701eb5589c4a0d5aa24 Mon Sep 17 00:00:00 2001 From: Silvano Luciani Date: Thu, 31 Jul 2014 10:44:08 -0700 Subject: [PATCH 1/2] TEST(datastore): add regression test for filtering by key. --- regression/datastore.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/regression/datastore.js b/regression/datastore.js index eb7c50ea656..8db08131ee6 100644 --- a/regression/datastore.js +++ b/regression/datastore.js @@ -254,6 +254,16 @@ describe('datastore', function() { }); }); + it('should filter by key', function(done) { + var q = ds.createQuery('Character') + .filter('__key__ =', ['Character', 'Rickard']); + ds.runQuery(q, function(err, keys, objs, nextQuery) { + if (err) return done(err); + assert.equal(objs.length, 1); + done(); + }); + }); + it('should order queries', function(done) { var q = ds.createQuery('Character').order('+appearances'); ds.runQuery(q, function(err, keys, objs, nextQuery) { From f2b26dcb253f7269d3d8e348bd2d6731c3147f11 Mon Sep 17 00:00:00 2001 From: Silvano Luciani Date: Thu, 31 Jul 2014 11:11:55 -0700 Subject: [PATCH 2/2] DOCS(readme): add example for filtering by key in datastore. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 5cd5472dd5e..6a120370f76 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,14 @@ var q = ds.createQuery('Company') .filter('size <', 400); ~~~~ +To filter by key, use `__key__` for the property name. Filtering on keys +stored as properties is not currently supported. + +~~~~ js +var q = ds.createQuery('Company') + .filter('__key__ =', ['Company', 'Google']) +~~~~ + In order to filter by ancestors, use `hasAncestor` helper. ~~~ js