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 }; 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 = [