@@ -73,7 +73,7 @@ In principle, both options are a valid way to establish a One-To-One relationshi
...
@@ -73,7 +73,7 @@ In principle, both options are a valid way to establish a One-To-One relationshi
### Goal
### Goal
For the rest of this example, let's assume that we have two models, `Foo` and `Bar`. We want to setup a One-To-One relationship between them such that `Foo` gets a `barId` column.
For the rest of this example, let's assume that we have two models, `Foo` and `Bar`. We want to setup a One-To-One relationship between them such that `Bar` gets a `fooId` column.
### Implementation
### Implementation
...
@@ -84,7 +84,7 @@ Foo.hasOne(Bar);
...
@@ -84,7 +84,7 @@ Foo.hasOne(Bar);
Bar.belongsTo(Foo);
Bar.belongsTo(Foo);
```
```
Since no option was passed, Sequelize will infer what to do from the names of the models. In this case, Sequelize knows that a `barId` column must be added to `Foo`.
Since no option was passed, Sequelize will infer what to do from the names of the models. In this case, Sequelize knows that a `fooId` column must be added to `Bar`.
This way, calling `Bar.sync()` after the above will yield the following SQL (on PostgreSQL, for example):
This way, calling `Bar.sync()` after the above will yield the following SQL (on PostgreSQL, for example):
...
@@ -775,4 +775,4 @@ The trick to deciding between `sourceKey` and `targetKey` is just to remember wh
...
@@ -775,4 +775,4 @@ The trick to deciding between `sourceKey` and `targetKey` is just to remember wh
*`A.hasOne(B)` and `A.hasMany(B)` keep the foreign key in the target model (`B`), therefore the referenced key is in the source model, hence the usage of `sourceKey`.
*`A.hasOne(B)` and `A.hasMany(B)` keep the foreign key in the target model (`B`), therefore the referenced key is in the source model, hence the usage of `sourceKey`.
*`A.belongsToMany(B)` involves an extra table (the junction table), therefore both `sourceKey` and `targetKey` are usable, with `sourceKey` corresponding to some field in `A` (the source) and `targetKey` corresponding to some field in `B` (the target).
*`A.belongsToMany(B)` involves an extra table (the junction table), therefore both `sourceKey` and `targetKey` are usable, with `sourceKey` corresponding to some field in `A` (the source) and `targetKey` corresponding to some field in `B` (the target).