{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/2851","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/2851/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/2851/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/2851/events","html_url":"https://github.com/Automattic/mongoose/issues/2851","id":67171304,"number":2851,"title":"Multi-level discriminators","user":{"login":"vkarpov15","id":1620265,"avatar_url":"https://avatars2.githubusercontent.com/u/1620265?v=4","gravatar_id":"","url":"https://api.github.com/users/vkarpov15","html_url":"https://github.com/vkarpov15","followers_url":"https://api.github.com/users/vkarpov15/followers","following_url":"https://api.github.com/users/vkarpov15/following{/other_user}","gists_url":"https://api.github.com/users/vkarpov15/gists{/gist_id}","starred_url":"https://api.github.com/users/vkarpov15/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkarpov15/subscriptions","organizations_url":"https://api.github.com/users/vkarpov15/orgs","repos_url":"https://api.github.com/users/vkarpov15/repos","events_url":"https://api.github.com/users/vkarpov15/events{/privacy}","received_events_url":"https://api.github.com/users/vkarpov15/received_events","type":"User","site_admin":false},"labels":[{"id":12655261,"url":"https://api.github.com/repos/Automattic/mongoose/labels/new%20feature","name":"new feature","color":"e102d8","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":26,"created_at":"2015-04-08T16:44:41Z","updated_at":"2018-04-26T12:47:07Z","closed_at":null,"author_association":"COLLABORATOR","body":""},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/384628478","html_url":"https://github.com/Automattic/mongoose/issues/2851#issuecomment-384628478","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/2851","id":384628478,"user":{"login":"natanavra","id":4521300,"avatar_url":"https://avatars0.githubusercontent.com/u/4521300?v=4","gravatar_id":"","url":"https://api.github.com/users/natanavra","html_url":"https://github.com/natanavra","followers_url":"https://api.github.com/users/natanavra/followers","following_url":"https://api.github.com/users/natanavra/following{/other_user}","gists_url":"https://api.github.com/users/natanavra/gists{/gist_id}","starred_url":"https://api.github.com/users/natanavra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natanavra/subscriptions","organizations_url":"https://api.github.com/users/natanavra/orgs","repos_url":"https://api.github.com/users/natanavra/repos","events_url":"https://api.github.com/users/natanavra/events{/privacy}","received_events_url":"https://api.github.com/users/natanavra/received_events","type":"User","site_admin":false},"created_at":"2018-04-26T12:47:07Z","updated_at":"2018-04-26T12:47:07Z","author_association":"NONE","body":"Since there's still no support for this, I solved this by keeping a base model and exporting another schema to a separate file and then adding properties to it as needed.\r\n\r\nHope that helps:\r\n```js\r\n/** BaseModel.js **/\r\nconst mongoose = require('mongoose');\r\nconst myModel = new mongoose.Schema({\r\n\tname: {type: String, required: true},\r\n});\r\n\r\nmodule.exports = mongoose.model('Model', myModel);\r\n\r\n/** schema.js **/\r\nconst mongoose = require('mongoose');\r\nmodule.exports = function(props) {\r\n\tconst params = {\r\n\t\tdescription: {type: String}\r\n\t};\r\n\tif(props) Object.assign(params, props);\r\n\treturn new mongoose.Schema(params);\r\n};\r\n\r\n/** SubModel.js **/\r\nconst mongoose = require('mongoose');\r\nconst BaseModel = require('./BaseModel');\r\nconst BaseSchema = require('./schema');\r\n\r\nconst subModel = BaseSchema({\r\n    myProp: {type: Number}\r\n});\r\n\r\nmodule.exports = BaseModel.discriminator('SubModel', subModel);\r\n```\r\n\r\nYou create more sub models by creating more sub-schema factories."}}
{"actor":{"display_login":"natanavra"}}