{"action":"created","issue":{"url":"https://api.github.com/repos/overlookmotel/sequelize-hierarchy/issues/11","labels_url":"https://api.github.com/repos/overlookmotel/sequelize-hierarchy/issues/11/labels{/name}","comments_url":"https://api.github.com/repos/overlookmotel/sequelize-hierarchy/issues/11/comments","events_url":"https://api.github.com/repos/overlookmotel/sequelize-hierarchy/issues/11/events","html_url":"https://github.com/overlookmotel/sequelize-hierarchy/issues/11","id":59971820,"number":11,"title":"Support for non-primary key ids","user":{"login":"devlato","id":1210210,"avatar_url":"https://avatars.githubusercontent.com/u/1210210?v=3","gravatar_id":"","url":"https://api.github.com/users/devlato","html_url":"https://github.com/devlato","followers_url":"https://api.github.com/users/devlato/followers","following_url":"https://api.github.com/users/devlato/following{/other_user}","gists_url":"https://api.github.com/users/devlato/gists{/gist_id}","starred_url":"https://api.github.com/users/devlato/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devlato/subscriptions","organizations_url":"https://api.github.com/users/devlato/orgs","repos_url":"https://api.github.com/users/devlato/repos","events_url":"https://api.github.com/users/devlato/events{/privacy}","received_events_url":"https://api.github.com/users/devlato/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-05T15:58:43Z","updated_at":"2015-03-10T15:45:28Z","closed_at":null,"body":"Add support for customization of id field with additional option like `primaryKeyAttribute`, i.e.:\r\n```javascript\r\nmodule.exports = function(sequelize, DataTypes) {\r\n  var fields, model, settings;\r\n  fields = {\r\n    id: {\r\n      type: DataTypes.INTEGER.UNSIGNED,\r\n      allowNull: false,\r\n      primaryKey: true,\r\n      autoIncrement: true,\r\n      validate: {\r\n        isInt: true\r\n      }\r\n    },\r\n    createdAt: {\r\n      type: 'TIMESTAMP'\r\n    },\r\n    updatedAt: {\r\n      type: 'TIMESTAMP'\r\n    },\r\n    widgetType: {\r\n      type: DataTypes.STRING,\r\n      validate: {\r\n        notEmpty: true\r\n      }\r\n    },\r\n    parentId: {\r\n      type: DataTypes.INTEGER.UNSIGNED,\r\n      allowNull: true,\r\n      references: 'widget_instance',\r\n      referencesKey: 'id',\r\n      hierarchy: {\r\n        as: 'someId',\r\n        childrenAs: 'content',\r\n        primaryKeyAttribute: 'widgetInstancePublicId'\r\n      },\r\n      validate: {\r\n        isInt: true\r\n      }\r\n    },\r\n    hierarchyLevel: {\r\n      type: DataTypes.INTEGER.UNSIGNED,\r\n      allowNull: true\r\n    },\r\n    documentId: {\r\n      type: DataTypes.INTEGER.UNSIGNED,\r\n      references: 'document',\r\n      referencesKey: 'id',\r\n      validate: {\r\n        isInt: true\r\n      }\r\n    },\r\n    widgetInstancePublicId: {\r\n      type: DataTypes.INTEGER.UNSIGNED,\r\n      validate: {\r\n        isInt: true\r\n      }\r\n    }\r\n  };\r\n  settings = {\r\n    tableName: 'widget_instance'\r\n  };\r\n  model = sequelize.define('WidgetInstance', fields, settings);\r\n  return model;\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/overlookmotel/sequelize-hierarchy/issues/comments/78081552","html_url":"https://github.com/overlookmotel/sequelize-hierarchy/issues/11#issuecomment-78081552","issue_url":"https://api.github.com/repos/overlookmotel/sequelize-hierarchy/issues/11","id":78081552,"user":{"login":"overlookmotel","id":557937,"avatar_url":"https://avatars.githubusercontent.com/u/557937?v=3","gravatar_id":"","url":"https://api.github.com/users/overlookmotel","html_url":"https://github.com/overlookmotel","followers_url":"https://api.github.com/users/overlookmotel/followers","following_url":"https://api.github.com/users/overlookmotel/following{/other_user}","gists_url":"https://api.github.com/users/overlookmotel/gists{/gist_id}","starred_url":"https://api.github.com/users/overlookmotel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/overlookmotel/subscriptions","organizations_url":"https://api.github.com/users/overlookmotel/orgs","repos_url":"https://api.github.com/users/overlookmotel/repos","events_url":"https://api.github.com/users/overlookmotel/events{/privacy}","received_events_url":"https://api.github.com/users/overlookmotel/received_events","type":"User","site_admin":false},"created_at":"2015-03-10T15:45:28Z","updated_at":"2015-03-10T15:45:28Z","body":"OK, but can you give me an fuller explanation of why you'd want to do this? The idea of a hierarchy is that each \"node\" in the tree has a single parent, so why wouldn't the `parentId` refer to the primary key of that parent?\r\n\r\nConcerning my question \"if `parentId.hierarchy.primaryKeyAttribute` = `'widgetInstancePublicId'`, shoudn't `parentId.referencesKey` = `'widgetInstancePublicId'` too\": I'm not clear from your answer whether there was a typo in the original code you posted (where `parentId.referencesKey` = `'id'`) or if I'm missing something.\r\n\r\nPlease help me to understand what you're trying to do..."}}