Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure bulk create returns plain objects when lean is 'true' #186

Merged
merged 3 commits into from
Aug 14, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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