Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User.hasMany(Task); // 将会添加 userId 到 Task 模型,实际却是加的UserId #16

Open
kingzez opened this issue Sep 10, 2018 · 0 comments

Comments

@kingzez
Copy link

kingzez commented Sep 10, 2018

https://github.com/demopark/sequelize-docs-Zh-CN/blob/master/associations.md#%E5%A4%96%E9%94%AE

外键

当您在模型中创建关联时,会自动创建带约束的外键引用。 下面是设置:

const Task = sequelize.define('task', { title: Sequelize.STRING });
const User = sequelize.define('user', { username: Sequelize.STRING });

User.hasMany(Task); // 将会添加 userId 到 Task 模型
Task.belongsTo(User); // 也将会添加 userId 到 Task 模型
@kingzez kingzez changed the title User.hasMany(Task); // 将会添加 userId 到 Task 模型,实际却是加的USERID User.hasMany(Task); // 将会添加 userId 到 Task 模型,实际却是加的USERId Sep 10, 2018
@kingzez kingzez changed the title User.hasMany(Task); // 将会添加 userId 到 Task 模型,实际却是加的USERId User.hasMany(Task); // 将会添加 userId 到 Task 模型,实际却是加的UserId Sep 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant