{"action":"created","issue":{"url":"https://api.github.com/repos/eggjs/egg/issues/729","repository_url":"https://api.github.com/repos/eggjs/egg","labels_url":"https://api.github.com/repos/eggjs/egg/issues/729/labels{/name}","comments_url":"https://api.github.com/repos/eggjs/egg/issues/729/comments","events_url":"https://api.github.com/repos/eggjs/egg/issues/729/events","html_url":"https://github.com/eggjs/egg/issues/729","id":220399265,"number":729,"title":"egg-sequelize 建立表之间的外键,  最好能提供完整的mysql用例","user":{"login":"yugasun","id":8536173,"avatar_url":"https://avatars3.githubusercontent.com/u/8536173?v=3","gravatar_id":"","url":"https://api.github.com/users/yugasun","html_url":"https://github.com/yugasun","followers_url":"https://api.github.com/users/yugasun/followers","following_url":"https://api.github.com/users/yugasun/following{/other_user}","gists_url":"https://api.github.com/users/yugasun/gists{/gist_id}","starred_url":"https://api.github.com/users/yugasun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yugasun/subscriptions","organizations_url":"https://api.github.com/users/yugasun/orgs","repos_url":"https://api.github.com/users/yugasun/repos","events_url":"https://api.github.com/users/yugasun/events{/privacy}","received_events_url":"https://api.github.com/users/yugasun/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2017-04-08T13:17:44Z","updated_at":"2017-05-09T01:07:49Z","closed_at":"2017-04-10T02:48:45Z","body":"最近在构建users 和userprofiles表之间构建relationship的时候，一直无法自动创建userprofiles中的外键user_id, 按照官方用例已经分别创建文件文件：\r\n\r\napp/model/user.js:\r\n\r\n```javascript\r\nmodule.exports = app => {\r\n  const {\r\n    STRING,\r\n    INTEGER,\r\n    BOOLEAN,\r\n    DATE\r\n  } = app.Sequelize;\r\n\r\n  const User = app.model.define('User', {\r\n    username: {\r\n      type: STRING(30),\r\n      unique: true\r\n    },\r\n    password: STRING(72),\r\n    companyName: STRING(255),\r\n    accountExpired: BOOLEAN,\r\n    passwordExpired: BOOLEAN\r\n  }, {\r\n    classMethods: {\r\n      associate() {\r\n        User.hasOne(app.model.UserProfile);\r\n      }\r\n    }\r\n  });\r\n\r\n  User.sync({force: true})\r\n  return User;\r\n}\r\n```\r\n\r\napp/model/userProfile.js:\r\n\r\n```javascript\r\nmodule.exports = app => {\r\n  const {\r\n    STRING,\r\n    INTEGER,\r\n    BOOLEAN,\r\n    DATE\r\n  } = app.Sequelize;\r\n\r\n  const UserProfile = app.model.define('UserProfile', {\r\n    name: STRING(64),\r\n    address: STRING(255),\r\n    email: {\r\n      type: STRING(64),\r\n      isEmail: true\r\n    },\r\n    birthDay: DATE,\r\n    currentCity: STRING(255),\r\n    currentCountry: STRING(255),\r\n  }, {\r\n    classMethods: {\r\n      associate() {\r\n        UserProfile.belongsTo(app.model.User);\r\n      }\r\n    }\r\n  });\r\n   UserProfile.sync({force: true})\r\n  return UserProfile;\r\n}\r\n\r\n```\r\n\r\n虽然两张表能顺利的创建起来，但是两个表之间并没有简历关联希望官方对于插件 `egg-sequelize` 给出详细点的实例。"},"comment":{"url":"https://api.github.com/repos/eggjs/egg/issues/comments/300032809","html_url":"https://github.com/eggjs/egg/issues/729#issuecomment-300032809","issue_url":"https://api.github.com/repos/eggjs/egg/issues/729","id":300032809,"user":{"login":"a304885433","id":3955567,"avatar_url":"https://avatars2.githubusercontent.com/u/3955567?v=3","gravatar_id":"","url":"https://api.github.com/users/a304885433","html_url":"https://github.com/a304885433","followers_url":"https://api.github.com/users/a304885433/followers","following_url":"https://api.github.com/users/a304885433/following{/other_user}","gists_url":"https://api.github.com/users/a304885433/gists{/gist_id}","starred_url":"https://api.github.com/users/a304885433/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/a304885433/subscriptions","organizations_url":"https://api.github.com/users/a304885433/orgs","repos_url":"https://api.github.com/users/a304885433/repos","events_url":"https://api.github.com/users/a304885433/events{/privacy}","received_events_url":"https://api.github.com/users/a304885433/received_events","type":"User","site_admin":false},"created_at":"2017-05-09T01:07:49Z","updated_at":"2017-05-09T01:07:49Z","body":"@SF-Zhou 最近发现，原来挂载sequelize 的sync方法，被移植到了 app.Model.sync 这样可以同步所有表结构了。"}}
{"actor":{"display_login":"a304885433"}}