{"action":"created","issue":{"url":"https://api.github.com/repos/neumino/thinky/issues/453","repository_url":"https://api.github.com/repos/neumino/thinky","labels_url":"https://api.github.com/repos/neumino/thinky/issues/453/labels{/name}","comments_url":"https://api.github.com/repos/neumino/thinky/issues/453/comments","events_url":"https://api.github.com/repos/neumino/thinky/issues/453/events","html_url":"https://github.com/neumino/thinky/issues/453","id":137562317,"number":453,"title":"Extending model","user":{"login":"trunda","id":466388,"avatar_url":"https://avatars.githubusercontent.com/u/466388?v=3","gravatar_id":"","url":"https://api.github.com/users/trunda","html_url":"https://github.com/trunda","followers_url":"https://api.github.com/users/trunda/followers","following_url":"https://api.github.com/users/trunda/following{/other_user}","gists_url":"https://api.github.com/users/trunda/gists{/gist_id}","starred_url":"https://api.github.com/users/trunda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trunda/subscriptions","organizations_url":"https://api.github.com/users/trunda/orgs","repos_url":"https://api.github.com/users/trunda/repos","events_url":"https://api.github.com/users/trunda/events{/privacy}","received_events_url":"https://api.github.com/users/trunda/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-03-01T12:34:28Z","updated_at":"2016-03-15T10:28:26Z","closed_at":null,"body":"This is more like question than issue.\r\n\r\nI did somethink like this:\r\n\r\n```\r\nimport Thinky, {type} from 'thinky';\r\nimport Model from 'thinky/lib/model';\r\nimport config from '../config';\r\nimport { parse as parseSchema } from 'thinky/lib/schema';\r\nimport _ from 'lodash';\r\n\r\nconst thinky = Thinky(config.rethinkdb);\r\nconst r = thinky.r;\r\n\r\nModel.prototype.timestamps = function timestamps(createdAt = 'createdAt', updatedAt = 'updatedAt') {\r\n  const { _schema: schema } = parseSchema({\r\n    createdAt: type.date().allowNull(false),\r\n    updatedAt: type.date().allowNull(false),\r\n  }, '', this._options, this);\r\n  this._schema._schema = _.merge(this._schema._schema, schema);\r\n  this.pre('save', function (next) {\r\n    if (!this.isSaved()) {\r\n      this.createdAt = r.now();\r\n    }\r\n\r\n    this.updatedAt = r.now();\r\n    next();\r\n  });\r\n};\r\n\r\nexport { r, thinky, type };\r\nexport default thinky;\r\n```\r\n\r\nAnd then in model definition:\r\n\r\n```\r\nimport { thinky, r, type } from './thinky';\r\n\r\nconst User = thinky.createModel('Users', {\r\n  id: type.string(),\r\n  name: type.string(),\r\n  email: type.string(),\r\n  password: type.string(),\r\n});\r\n\r\nUser.timestamps();\r\n\r\nexport default User;\r\n```\r\n\r\nEverything works like expected, but question is, is this duck-typing secure and good way to solve this kind of problems (extending model functionality)?"},"comment":{"url":"https://api.github.com/repos/neumino/thinky/issues/comments/196757540","html_url":"https://github.com/neumino/thinky/issues/453#issuecomment-196757540","issue_url":"https://api.github.com/repos/neumino/thinky/issues/453","id":196757540,"user":{"login":"trunda","id":466388,"avatar_url":"https://avatars.githubusercontent.com/u/466388?v=3","gravatar_id":"","url":"https://api.github.com/users/trunda","html_url":"https://github.com/trunda","followers_url":"https://api.github.com/users/trunda/followers","following_url":"https://api.github.com/users/trunda/following{/other_user}","gists_url":"https://api.github.com/users/trunda/gists{/gist_id}","starred_url":"https://api.github.com/users/trunda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trunda/subscriptions","organizations_url":"https://api.github.com/users/trunda/orgs","repos_url":"https://api.github.com/users/trunda/repos","events_url":"https://api.github.com/users/trunda/events{/privacy}","received_events_url":"https://api.github.com/users/trunda/received_events","type":"User","site_admin":false},"created_at":"2016-03-15T10:28:26Z","updated_at":"2016-03-15T10:28:26Z","body":"Hi @vpanghal, i did it [this way](https://gist.github.com/trunda/20da56e66753500d1d9c#file-models-thinky-js). Simply said I monkey patched the thinky.createModel method to to accept `concerns`."}}