Skip to content

Commit

Permalink
Merge pull request #430 from stephenplusplus/spp--unindexed-lists
Browse files Browse the repository at this point in the history
datastore: allow indexing list values
  • Loading branch information
ryanseys committed Mar 5, 2015
2 parents 1a7737b + d6287a2 commit e6b9485
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/datastore/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,15 @@ DatastoreRequest.prototype.save = function(entities, callback) {
data.value = entity.valueToProperty(data.value);

if (util.is(data.excludeFromIndexes, 'boolean')) {
data.value.indexed = !data.excludeFromIndexes;
var indexed = !data.excludeFromIndexes;

if (util.is(data.value.list_value, 'array')) {
data.value.list_value =
data.value.list_value.map(util.propAssign('indexed', indexed));
} else {
data.value.indexed = indexed;
}

delete data.excludeFromIndexes;
}

Expand Down
21 changes: 21 additions & 0 deletions test/datastore/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,27 @@ describe('Request', function() {
}, assert.ifError);
});

it('should allow setting the indexed value on arrays', function(done) {
request.makeReq_ = function(method, req) {
var property = req.mutation.upsert[0].property[0];

property.value.list_value.forEach(function(value) {
assert.strictEqual(value.indexed, false);
});

done();
};

request.save({
key: key,
data: [{
name: 'name',
value: ['one', 'two', 'three'],
excludeFromIndexes: true
}]
}, assert.ifError);
});

describe('transactions', function() {
beforeEach(function() {
// Trigger transaction mode.
Expand Down

0 comments on commit e6b9485

Please sign in to comment.