Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/bag.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function Bag (serialized) {
this._offset = 0;
this._current = -1;
this._size = null;
this._prefetchedRecords = null;
}

Bag.BAG_EMBEDDED = 0;
Expand Down Expand Up @@ -133,7 +134,12 @@ Bag.prototype.next = function () {
}
this._current++;
rid = this._consume();
this._content.push(rid);
if (this._prefetchedRecords && this._prefetchedRecords[rid]) {
this._content.push(this._prefetchedRecords[rid]);
}
else {
this._content.push(rid);
}
return rid;
}
};
Expand Down
6 changes: 6 additions & 0 deletions lib/db/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var Promise = require('bluebird'),
RID = require('../recordid'),
RIDBag = require('../bag'),
errors = require('../errors');

/**
Expand Down Expand Up @@ -150,6 +151,11 @@ function recordIdResolver () {
/*jshint validthis:true */
return obj.map(replaceRecordIds.bind(this, records));
}
else if (obj instanceof RIDBag) {
/*jshint validthis:true */
obj._prefetchedRecords = records;
return obj;
}
else if (obj instanceof RID && records[obj]) {
return records[obj];
}
Expand Down
4 changes: 2 additions & 2 deletions test/core/bag-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe("RID Bag", function () {
var contents = this.bag.all();
contents.length.should.equal(10);
contents.forEach(function (item) {
item.should.be.an.instanceOf(LIB.RID);
item.should.have.property('@rid');
});
});

Expand All @@ -83,7 +83,7 @@ describe("RID Bag", function () {
decoded = JSON.parse(json);
decoded.length.should.equal(10);
decoded.forEach(function (item) {
(typeof item).should.equal('string');
item.should.have.property('@rid');
});
});
});
Expand Down