Skip to content

Commit

Permalink
Ensure bulk create returns plain objects when lean is 'true' (#186)
Browse files Browse the repository at this point in the history
* Ensure bulk create returns plain objects when lean is 'true'

* Bump version number for feathers-service-tests
  • Loading branch information
DesignByOnyx authored and daffl committed Aug 14, 2017
1 parent be7d9e4 commit 2f9e0b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,15 @@ class Service {
const discriminator = data[this.discriminatorKey] || this.discriminatorKey;
const model = this.discriminators[discriminator] || this.Model;
return model.create(data)
.then(result => (this.lean && result.toObject) ? result.toObject() : result)
.then(result => {
if (this.lean) {
if (Array.isArray(result)) {
return result.map(item => (item.toObject ? item.toObject() : item));
}
return result.toObject ? result.toObject() : result;
}
return result;
})
.then(select(params, this.id))
.catch(errorHandler);
}
Expand Down
4 changes: 3 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-unused-expressions */

import { expect } from 'chai';
import { base, example } from 'feathers-service-tests';
import { base, example, orm } from 'feathers-service-tests';
import errors from 'feathers-errors';
import feathers from 'feathers';
import service, { hooks, Service } from '../src';
Expand Down Expand Up @@ -334,6 +334,8 @@ describe('Feathers Mongoose Service', () => {
done();
});
});

orm(leanPeople, errors, '_id');
});

describe('Lean Services', () => {
Expand Down

0 comments on commit 2f9e0b7

Please sign in to comment.