Commit de4ac246 authored by Dian Fay's avatar Dian Fay
Browse files

docs: warn about join limitations with count and limit

parent db773221
Pipeline #245949494 passed with stages
in 1 minute and 40 seconds
......@@ -74,6 +74,11 @@ Readable.prototype.aliasField = function (field) {
* @return {Promise} Row count.
*/
Readable.prototype.count = function (conditions = {}, params = []) {
if (this.loader === 'join') {
/* eslint-disable-next-line no-console */
console.warn('WARNING: counting a join relation will yield unexpected results.');
}
if (_.isString(conditions)) {
conditions = {
conditions,
......
......@@ -34,6 +34,11 @@ const Select = function (source, criteria = {}, options = {}) {
this.pageLength = options.pageLength;
this.lock = this.parseLock(options);
if (options.limit && source.loader === 'join') {
/* eslint-disable-next-line no-console */
console.warn('WARNING: setting LIMIT on join queries may truncate results and give the appearance of missing data.');
}
// with pageLength set for keyset pagination, add last values of ordering
// fields to criteria
if (this.pageLength) {
......
......@@ -1368,11 +1368,52 @@ describe('join', function () {
});
describe('useless methods', function () {
/* eslint-disable no-console */
const _warn = console.warn;
after(function () {
console.warn = _warn;
});
it('warns on count', function () {
let warned = false;
console.warn = msg => {
assert.equal(msg, 'WARNING: counting a join relation will yield unexpected results.');
warned = true;
};
return db.alpha.join('beta')
.count()
.then(() => {
assert.isTrue(warned);
});
});
it('warns on limit', function () {
let warned = false;
console.warn = msg => {
assert.equal(msg, 'WARNING: setting LIMIT on join queries may truncate results and give the appearance of missing data.');
warned = true;
};
return db.alpha.join('beta')
.find({}, {
limit: 10
})
.then(() => {
assert.isTrue(warned);
});
});
it('errors on findOne', function () {
return db.alpha.join('beta')
.findOne({})
.then(() => assert.fail())
.catch(err => assert.equal(err.message, 'findOne is not supported with compound Readables.'));
});
/* eslint-enable no-console */
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment