不要怂,就是干,撸起袖子干!

Commit e9b9849e by Bulkan Evcimen

Mention the `foreignKey` option with belongsToMany

1 parent 01d86c28
Showing with 3 additions and 3 deletions
...@@ -143,10 +143,10 @@ Defining `through` is required. Sequelize would previously attempt to autogenera ...@@ -143,10 +143,10 @@ Defining `through` is required. Sequelize would previously attempt to autogenera
This will add methods `getUsers`, `setUsers`, `addUsers` to `Project`, and `getProjects`, `setProjects` and `addProject` to `User`. This will add methods `getUsers`, `setUsers`, `addUsers` to `Project`, and `getProjects`, `setProjects` and `addProject` to `User`.
Sometimes you may want to rename your models when using them in associations. Let's define users as workers and projects as tasks by using the alias (`as`) option: Sometimes you may want to rename your models when using them in associations. Let's define users as workers and projects as tasks by using the alias (`as`) option. We will also manually define the foreign keys to use:
```js ```js
User.belongsToMany(Project, { as: 'Tasks', through: 'worker_tasks' }) User.belongsToMany(Project, { as: 'Tasks', through: 'worker_tasks', foreignKey: 'userId' })
Project.belongsToMany(User, { as: 'Workers', through: 'worker_tasks' }) Project.belongsToMany(User, { as: 'Workers', through: 'worker_tasks', foreignKey: 'projectId' })
``` ```
Of course you can also define self references with belongsToMany: Of course you can also define self references with belongsToMany:
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!