-
Notifications
You must be signed in to change notification settings - Fork 648
Description
I asked this question on stackoverflow, but am also posting here as an issue (http://stackoverflow.com/questions/37401751/cant-save-and-delete-in-a-transaction).
var cachedTransaction;
datastore.runInTransaction(function(transaction, done) {
cachedTransaction = transaction;
var keys = [
datastore.key([PARENT_TABLE, p1]),
datastore.key([PARENT_TABLE, p2]),
datastore.key([PARENT_TABLE, p1, CHILD_TABLE, p2])
];
transaction.get(keys, function(err, entities) {
if (err) {
transaction.rollback();
}
if (entities) {
transaction.save([{
key: datastore.key([PARENT_TABLE, p1]),
method: 'update',
data: {
p: 100
}
}, {
key: datastore.key([config.PARENT_TABLE, p2]),
method: 'update',
data: {
p: 100
}
}]);
transaction.delete([
datastore.key([PARENT_TABLE, p1, CHILD_TABLE, p2]),
datastore.key([PARENT_TABLE, p2, CHILD_TABLE, p1])
]);
} else {
console.log('Entities are empty');
}
console.log('commiting ... ');
done();
console.log('commited ');
} else {
transaction.rollback();
}
});
},
function(err) {
console.log('commited complete. Was it successful ? ');
if (err) {
console.log('err : ' + err);
cachedTransaction.rollback();
}
});
With the following code I am getting two entities from a parent table and one entity from a child table (I print some stuff with this child entity not shown in code). I then update the two parent entities and delete two child entities (one which I did not get get from my original response). The result is that the parent entities do get updated, but the two children entities do NOT get deleted. I get no error messages.
If I comment out the save portion of the code which updated the parents, then it will delete the child entities, but I need to update the parent and delete the children. How can I do this? I am using gcloud-node 0.34.0 and running off the actual Google Cloud Datastore.
Thanks!