-
Notifications
You must be signed in to change notification settings - Fork 96
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
patch model with a discriminator #259
Comments
After reading through the source tests and understanding the proper way to set up discriminators, I've resolved my issue. For anyone facing a similar problem in the future, read the tests! Heh... thanks for the thorough docs and great work in general @ core-team ;) For those interested, the following changes did the trick:
Updated src/models/people.model.js module.exports = function (app) {
const mongooseClient = app.get('mongooseClient');
const { Schema } = mongooseClient;
// Added options to be supplied to both schemas
const options = {
discriminatorKey: '_type'
}
const PersonSchema = new Schema({
name: { type: String, required: true }
}, options);
const ClientSchema = new Schema({
isProspect: Boolean
}, options);
const PersonModel = mongooseClient.model('people', PersonSchema);
// Needs to be supplied to `discriminators` array in `people` service options
const ClientModel = PersonModel.discriminator('client', ClientSchema);
// Exporting as object to be destructured in `src/services/people/people.service.js`
return {PersonModel, ClientModel};
}; Updated src/service/people/people.service const createService = require('feathers-mongoose');
const createModel = require('../../models/person.model');
module.exports = function (app) {
const {PersonModel, ClientModel} = createModel(app);
const options = {
Model: PersonModel,
discriminators: [ClientModel]
};
app.use('/people', createService(options));
app.service('people');
}; Finally, supply |
Steps to reproduce
Using @feathers/cli@v.3.8.0
src/models/people.model.js
test/services/people.test.js
Expected behavior
The last test should pass.
Actual behavior
The last test fails.
System configuration
Module versions (especially the part that's not working):
Module versions:
feathers-mongoose: 6.1.4
mongoose: 5.2.14
NodeJS version: 10.1.0
Operating System: Ubuntu 16.04
The text was updated successfully, but these errors were encountered: