{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/1243","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/1243/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/1243/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/1243/events","html_url":"https://github.com/sequelize/sequelize/issues/1243","id":25469599,"number":1243,"title":"Support InheritsFrom association","user":{"login":"ludydoo","id":38968,"avatar_url":"https://avatars.githubusercontent.com/u/38968?v=3","gravatar_id":"","url":"https://api.github.com/users/ludydoo","html_url":"https://github.com/ludydoo","followers_url":"https://api.github.com/users/ludydoo/followers","following_url":"https://api.github.com/users/ludydoo/following{/other_user}","gists_url":"https://api.github.com/users/ludydoo/gists{/gist_id}","starred_url":"https://api.github.com/users/ludydoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ludydoo/subscriptions","organizations_url":"https://api.github.com/users/ludydoo/orgs","repos_url":"https://api.github.com/users/ludydoo/repos","events_url":"https://api.github.com/users/ludydoo/events{/privacy}","received_events_url":"https://api.github.com/users/ludydoo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sequelize/sequelize/labels/feature","name":"feature","color":"0b02e1"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":90,"created_at":"2014-01-12T20:52:43Z","updated_at":"2016-08-24T15:12:53Z","closed_at":null,"body":"I am using sequelize but ran into the problem of it not supporting model inheritance.\r\n\r\nI would suggest implementing an InheritsFrom association, that would be basically the same as the BelongsTo association. Though, when persisting a new object, sequelize  would chain-create all subclass objects and persist them first. It would also allow an object to share the getters/setters of its superclass instances.\r\n\r\n```\r\n  module.exports = (function() {\r\n  var InheritsFrom = function(source, target, options) {\r\n    this.associationType      = 'InheritsFrom'\r\n    this.source               = source\r\n    this.target               = target\r\n    this.options              = options\r\n    this.isSingleAssociation  = true\r\n    this.isSelfAssociation    = false\r\n    this.as                   = this.options.as\r\n```\r\n\r\nI figured I could add the InheritsFrom and Superclasses options to the dao-factory.js,\r\nAlso, I would add InheritsFromInstance and SuperClassInstance in the dao.js\r\n\r\n```\r\n  var DAOFactory = function(name, attributes, options) {\r\n    this.options = Utils._.extend({\r\n      timestamps: true,\r\n      ...\r\n      inheritsFrom : null\r\n      superClasses : {}\r\n    }, options || {})\r\n```\r\n\r\nCalling the dao get from a inherited dao would look for the key, and if it was not found, look for the key in the sub dao, until it finds the correct  getter. Also, if a getter/setter was called from a superclass dao, it would find the last inherited dao, and start to find the key from there. \r\n\r\n```\r\nDAO.prototype.get = function (key) {\r\n    if (key) {\r\n      if (this._customGetters[key]) {\r\n        return this._customGetters[key].call(this, key)\r\n      }\r\n      return this.dataValues[key]\r\n    }\r\n\r\n    if (this._hasCustomGetters) {\r\n      var values = {}\r\n        , key\r\n\r\n      for (key in this._customGetters) {\r\n        if (this._customGetters.hasOwnProperty(key)) {\r\n          values[key] = this.get(key)\r\n        }\r\n      }\r\n\r\n      for (key in this.dataValues) {\r\n        if (!values.hasOwnProperty(key) && this.dataValues.hasOwnProperty(key)) {\r\n          values[key] = this.dataValues[key]\r\n        }\r\n      }\r\n      return values\r\n    }\r\n\r\n    //Here, check if the superclass has the get methods\r\n\r\n    return this.dataValues\r\n  }\r\n```\r\n\r\nI think I have to add some _customGetters and _customSetters in the dao-factory.js, but could somebody help me out and point me where in the codebase should I add such functionality? There is very few comments in there!\r\n\r\nPlease comment !"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/242099875","html_url":"https://github.com/sequelize/sequelize/issues/1243#issuecomment-242099875","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/1243","id":242099875,"user":{"login":"thomas-p-wilson","id":597691,"avatar_url":"https://avatars.githubusercontent.com/u/597691?v=3","gravatar_id":"","url":"https://api.github.com/users/thomas-p-wilson","html_url":"https://github.com/thomas-p-wilson","followers_url":"https://api.github.com/users/thomas-p-wilson/followers","following_url":"https://api.github.com/users/thomas-p-wilson/following{/other_user}","gists_url":"https://api.github.com/users/thomas-p-wilson/gists{/gist_id}","starred_url":"https://api.github.com/users/thomas-p-wilson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomas-p-wilson/subscriptions","organizations_url":"https://api.github.com/users/thomas-p-wilson/orgs","repos_url":"https://api.github.com/users/thomas-p-wilson/repos","events_url":"https://api.github.com/users/thomas-p-wilson/events{/privacy}","received_events_url":"https://api.github.com/users/thomas-p-wilson/received_events","type":"User","site_admin":false},"created_at":"2016-08-24T15:12:53Z","updated_at":"2016-08-24T15:12:53Z","body":"Yep. Thinking I'll pull 4.x down tonight or tomorrow evening and muck about with it a bit."}}
{"actor":{"display_login":"thomas-p-wilson"}}