{"action":"opened","issue":{"url":"https://api.github.com/repos/goto-bus-stop/mongoose-model-decorators/issues/3","repository_url":"https://api.github.com/repos/goto-bus-stop/mongoose-model-decorators","labels_url":"https://api.github.com/repos/goto-bus-stop/mongoose-model-decorators/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/goto-bus-stop/mongoose-model-decorators/issues/3/comments","events_url":"https://api.github.com/repos/goto-bus-stop/mongoose-model-decorators/issues/3/events","html_url":"https://github.com/goto-bus-stop/mongoose-model-decorators/issues/3","id":132997275,"number":3,"title":"Allow custom constructors","user":{"login":"dotlouis","id":1891109,"avatar_url":"https://avatars.githubusercontent.com/u/1891109?v=3","gravatar_id":"","url":"https://api.github.com/users/dotlouis","html_url":"https://github.com/dotlouis","followers_url":"https://api.github.com/users/dotlouis/followers","following_url":"https://api.github.com/users/dotlouis/following{/other_user}","gists_url":"https://api.github.com/users/dotlouis/gists{/gist_id}","starred_url":"https://api.github.com/users/dotlouis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotlouis/subscriptions","organizations_url":"https://api.github.com/users/dotlouis/orgs","repos_url":"https://api.github.com/users/dotlouis/repos","events_url":"https://api.github.com/users/dotlouis/events{/privacy}","received_events_url":"https://api.github.com/users/dotlouis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-11T15:07:45Z","updated_at":"2016-02-11T15:07:45Z","closed_at":null,"body":"Hi,\r\nMaybe this question has a broader scope than this module,\r\nbut I was wondering if it's possible to create a custom constructor for a Model class.\r\nI saw [in your code](https://github.com/goto-bus-stop/mongoose-model-decorators/blob/master/src/Schema.js#L13) that you were ignoring the constructor method.\r\n\r\nBasically I want to be able to do this:\r\n```js\r\n@Model\r\nclass Event{\r\n\r\n\tstatic schema = {\r\n\t\tstart: { type: Date, required: true },\r\n\t\tend: { type: Date, required: true },\r\n\t\tduration: { type: String, required: true },\r\n\t};\r\n\r\n\tconstructor(params = {}){\r\n\r\n        // set complex defaults, computed properties, validate params and more\r\n\t\tlet start = moment(params.start) || moment();\r\n\t\tlet duration = moment.duration(params.duration) || moment.duration(1,'h');\r\n\t\tlet end = moment(params.end) || moment(start).add(duration);\r\n\r\n        // somehow call the Mongoose model constructor with 'this' as an argument\r\n\t}\r\n}\r\n```\r\n\r\nI'm aware that Mongoose already have validators, default properties and virtuals properties.\r\nBut doing this things through a constructor feels more *natural*  and less dependant on how Mongoose works (through a Schema).\r\nBesides, it lets you work with properties in your model that you don't always want to be persisted in Mongo.\r\nFor example here I want to be able to call my Event constructor like so:\r\n```js\r\n// no params, defaults will apply (start is now, duration is 1h and end computed)\r\nnew Event();\r\n// a start and a duration (end is computed)\r\nnew Event(new Date(),'3h'); \r\n// a start and end (duration is computed)\r\nnew Event(new Date(),new Date()+10000);\r\n```\r\nI also want my server to be able to work directly with moment objects without having to convert Dates back and forth at saving time.\r\n\r\nHere, I think it's a little confusing. Maybe I'm horribly wrong, but it definitely felt like this was the most natural way of creating an Event.\r\nOpinions and advices are welcome.\r\nThanks"}}