Skip to content

Commit

Permalink
Merge pull request #110 from appscot/bug-expand
Browse files Browse the repository at this point in the history
When expanding results (in joins) make sure to only cache RIDs
  • Loading branch information
dmarcelino committed Jun 3, 2015
2 parents 5319453 + 488a5f5 commit c41e67c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/associations.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ Associations.prototype.expandResults = function expandResults(resultset) {
var clonedResults = _.cloneDeep(resultset);

var recordMap = utils.reduceNestedObjects(clonedResults, function(accumulator, obj){
if(obj.id)
if(obj.id && utils.matchRecordId(obj.id))
accumulator[obj.id] = _.cloneDeep(obj); // ugly but avoids circular references issues when converting to json
if(obj['@rid'])
log.warn('fetchPlanJoin: object ' + obj['@rid'] + ' still has @rid!');
Expand Down
15 changes: 15 additions & 0 deletions test/unit/associations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,19 @@ describe('associations class', function () {
done();
});

it('expandResults: should not confuse ids with rids', function(done){
var resultset = [
{ id: '#5:0', name: 'Maria', picture: { id: 1 }, likes: 1 }
];

var expandedResultset = [
{ id: '#5:0', name: 'Maria', picture: { id: 1 }, likes: 1 }
];

var transformed = associations.expandResults(resultset);
assert.deepEqual(transformed, expandedResultset);

done();
});

});

0 comments on commit c41e67c

Please sign in to comment.