diff --git a/lib/relations/RelationOwner.js b/lib/relations/RelationOwner.js index 53adb57bb..847637a6f 100644 --- a/lib/relations/RelationOwner.js +++ b/lib/relations/RelationOwner.js @@ -219,7 +219,7 @@ function containsNonNull(arr) { } function join(id) { - return id.join(','); + return id.map(x => (Buffer.isBuffer(x) ? x.toString('hex') : x)).join(','); } function isIdProp(relationProp) { diff --git a/tests/integration/misc/#1627.js b/tests/integration/misc/#1627.js index 3bd080e67..14643a6d4 100644 --- a/tests/integration/misc/#1627.js +++ b/tests/integration/misc/#1627.js @@ -90,5 +90,21 @@ module.exports = session => { expect(result).to.eql(inserted); }); + it('should fetch multiple relations correctly', async () => { + const ids = [ + Buffer.from('00000000000000000000000000007AAC', 'hex'), + Buffer.from('00000000000000000000000000007AAD', 'hex'), + Buffer.from('00000000000000000000000000007AAE', 'hex') + ]; + const graph = ids.map(id => ({ + id, + roles: [{ id: crypto.randomBytes(16) }] + })); + const inserted = await User.query().insertGraph(graph); + const result = await User.query() + .findByIds(ids) + .withGraphFetched('roles'); + expect(result).to.eql(inserted); + }); }); }; diff --git a/tests/unit/utils.js b/tests/unit/utils.js index f8468783c..f509d4f4d 100644 --- a/tests/unit/utils.js +++ b/tests/unit/utils.js @@ -12,7 +12,7 @@ const { const { range } = require('lodash'); const { compose, mixin } = require('../../lib/utils/mixin'); const { map } = require('../../lib/utils/promiseUtils'); -const { jsonEquals } = require('../../lib/utils/objectUtils'); +const { jsonEquals, uniqBy } = require('../../lib/utils/objectUtils'); describe('utils', () => { describe('mixin', () => { @@ -428,4 +428,22 @@ describe('utils', () => { ).to.equal(false); }); }); + describe('uniqBy', () => { + const items = [ + [Buffer.from('00000000000000000000000000007AAD', 'hex')], + [Buffer.from('00000000000000000000000000007AAE', 'hex')], + [Buffer.from('00000000000000000000000000007AAC', 'hex')] + ]; + it('should work with Buffer items', () => { + expect(uniqBy(items)).to.eql(items); + }); + it('should work with Buffer[] items', () => { + expect(uniqBy(items)).to.eql(items); + }); + it('should work with Buffer[] items with custom keyGetter function', () => { + expect( + uniqBy(items, item => item.map(x => (Buffer.isBuffer(x) ? x.toString('hex') : x)).join(',')) + ).to.eql(items); + }); + }); });