{"action":"closed","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/3586","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/3586/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/3586/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/3586/events","html_url":"https://github.com/Automattic/mongoose/issues/3586","id":117597326,"number":3586,"title":"validator not invoked when using discriminator","user":{"login":"thewilli","id":1206639,"avatar_url":"https://avatars.githubusercontent.com/u/1206639?v=3","gravatar_id":"","url":"https://api.github.com/users/thewilli","html_url":"https://github.com/thewilli","followers_url":"https://api.github.com/users/thewilli/followers","following_url":"https://api.github.com/users/thewilli/following{/other_user}","gists_url":"https://api.github.com/users/thewilli/gists{/gist_id}","starred_url":"https://api.github.com/users/thewilli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thewilli/subscriptions","organizations_url":"https://api.github.com/users/thewilli/orgs","repos_url":"https://api.github.com/users/thewilli/repos","events_url":"https://api.github.com/users/thewilli/events{/privacy}","received_events_url":"https://api.github.com/users/thewilli/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-18T14:24:31Z","updated_at":"2015-11-18T14:46:09Z","closed_at":"2015-11-18T14:46:09Z","body":"Consider the following code (slightly modified discriminator example), where a custom validator is defined on the `_id` field.\r\n\r\n```js\r\nvar options = { discriminatorKey: \"kind\" };\r\nvar eventSchema = new mongoose.Schema({\r\n    _id: {\r\n        type: String,\r\n        validate: {\r\n            validator: function(){\r\n                return false;\r\n            }\r\n        }\r\n    },\r\n    time: Date\r\n}, options);\r\nvar Event = mongoose.model(\"Event\", eventSchema);\r\nvar ClickedLinkSchema = new mongoose.Schema({\r\n    _id: false,\r\n    url: String\r\n}, options);\r\nvar ClickedLinkEvent = Event.discriminator(\"ClickedLink\", ClickedLinkSchema);\r\n```\r\n\r\nWhile the validator works for new `Event` documents, it is not invoked for `ClickedLinkEvent` docs:\r\n\r\n```js\r\n// document is not persisted due to validation error\r\nnew Event({_id: \"foo\"}).save(function(err){\r\n    if(err) throw err; \r\n});\r\n\r\n// document is persisted, even though it should not be\r\nnew ClickedLinkEvent({_id: \"foo\"}).save(function(err){\r\n    if(err) throw err; \r\n});\r\n```\r\n\r\nIs there any way to get mongoose to consider the `_id` validator for *inherited* schemas (without needing to redefine it)?"}}