From a20183bcd4d6fec2dd9b580f25df80fce82a5b0d Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Fri, 8 Aug 2014 11:52:03 -0700 Subject: [PATCH 1/2] Properties should detect keys and serialise them to key protos. --- lib/datastore/entity.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/datastore/entity.js b/lib/datastore/entity.js index 5f859153261..1533feb89e5 100644 --- a/lib/datastore/entity.js +++ b/lib/datastore/entity.js @@ -240,10 +240,13 @@ function valueToProperty(v) { }); return p; } + if (v instanceof Key) { + p.keyValue = keyToKeyProto(v); + return p; + } if (v instanceof Object && Object.keys(v).length > 0) { var properties = {}; Object.keys(v).forEach(function(k) { - // TODO: Detect keys? properties[k] = valueToProperty(v[k]); }); p.entityValue = { properties: properties }; From cb194ab3ba5ad436d812831f57d0a237059500cb Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Fri, 8 Aug 2014 12:34:41 -0700 Subject: [PATCH 2/2] datastore: Adding regression test for embedded key persistence and retrieval. --- regression/datastore.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/regression/datastore.js b/regression/datastore.js index 23608fa931b..eff6e16e3eb 100644 --- a/regression/datastore.js +++ b/regression/datastore.js @@ -122,6 +122,28 @@ describe('datastore', function() { }); + it('should be able to save keys as a part of entity and query by key', + function(done) { + var personKey = datastore.key('Person', 'name'); + ds.save({ + key: personKey, + data: { + fullName: 'Full name', + linkedTo: personKey // himself + } + }, function(err) { + assert.ifError(err); + var q = ds.createQuery('Person') + .filter('linkedTo =', personKey); + ds.runQuery(q, function(err, results) { + assert.ifError(err); + assert.strictEqual(results[0].data.fullName, 'Full name'); + assert.deepEqual(results[0].data.linkedTo, personKey); + ds.delete(personKey, done); + }); + }); + }); + describe('querying the datastore', function() { var keys = [