With Sequelize you can also specify associations between multiple classes. Doing so will help you to easily access and set those associated objects. The library therefore provides for each defined class different methods, which are explained in the following chapters.
## One-To-One associations
## One-To-One associations
One-To-One associations are associations between exactly two models connected by a single foreign key.
### BelongsTo
BelongsTo associations are associations where the foreign key for the one-to-one relation exists on the **source model**.
A simple example would be a **User** being part of a team **Team** with the foreign key on user.
User.belongsTo(Company,{foreignKey:'fk_company'});// Adds fk_company to User
```
### HasOne
HasOne associations are associations where the foreign key for the one-to-one relation exists on the **target model**.
One-To-One associations are connecting one source with exactly one target. In order to define a proper database schema, Sequelize utilizes the methods `belongsTo` and `hasOne`. You can use them as follows:
To get the association working the other way around (so from `User` to `Project`), it's necessary to do this:
Even though it is called a HasOne association, for most 1:1 relations you usually want the BelongsTo association since BelongsTo will add the foreignKey on the source where hasOne will add on the target.