René's URL Explorer Experiment


Title: Associations | Sequelize

Open Graph Title: Associations | Sequelize

Description: Sequelize supports the standard associations: One-To-One, One-To-Many and Many-To-Many.

Open Graph Description: Sequelize supports the standard associations: One-To-One, One-To-Many and Many-To-Many.

Opengraph URL: https://sequelize.org/docs/v6/core-concepts/assocs/

Generator: Docusaurus v3.6.1

direct link

Domain: sequelize.org

twitter:cardsummary_large_image
og:localeen
docusaurus_localeen
docsearch:languageen
docusaurus_version6.x.x
docusaurus_tagdocs-default-6.x.x
docsearch:version6.x.x
docsearch:docusaurus_tagdocs-default-6.x.x
None2

Links:

Skip to main contenthttps://sequelize.org/docs/v6/core-concepts/assocs/#__docusaurus_skipToContent_fallback
Sequelizehttps://sequelize.org/
v6 - stablehttps://sequelize.org/docs/v6/core-concepts/assocs/
v7 - alphahttps://sequelize.org/docs/v7/
v6 - stablehttps://sequelize.org/docs/v6/core-concepts/assocs/
v5https://sequelize.org/v5
v4https://sequelize.org/v4
v3https://sequelize.org/v3
v2https://sequelize.org/v2
v1https://sequelize.org/v1
API Referenceshttps://sequelize.org/docs/v6/core-concepts/assocs/
Sequelize 7https://sequelize.org/api/v7
Sequelize 6https://sequelize.org/api/v6/identifiers
Sequelize 5https://sequelize.org/v5/identifiers
Sequelize 4https://sequelize.org/v4/identifiers
Sequelize 3https://sequelize.org/v3/api/sequelize
Sequelize 2https://sequelize.org/v2/api/sequelize
Slackhttps://sequelize.org/slack
GitHubhttps://github.com/sequelize/sequelize
Securityhttps://github.com/sequelize/sequelize/blob/main/SECURITY.md
Introductionhttps://sequelize.org/docs/v6/
Getting Startedhttps://sequelize.org/docs/v6/getting-started/
Core Conceptshttps://sequelize.org/docs/v6/category/core-concepts/
Model Basicshttps://sequelize.org/docs/v6/core-concepts/model-basics/
Model Instanceshttps://sequelize.org/docs/v6/core-concepts/model-instances/
Model Querying - Basicshttps://sequelize.org/docs/v6/core-concepts/model-querying-basics/
Model Querying - Findershttps://sequelize.org/docs/v6/core-concepts/model-querying-finders/
Getters, Setters & Virtualshttps://sequelize.org/docs/v6/core-concepts/getters-setters-virtuals/
Validations & Constraintshttps://sequelize.org/docs/v6/core-concepts/validations-and-constraints/
Raw Querieshttps://sequelize.org/docs/v6/core-concepts/raw-queries/
Associationshttps://sequelize.org/docs/v6/core-concepts/assocs/
Paranoidhttps://sequelize.org/docs/v6/core-concepts/paranoid/
Advanced Association Conceptshttps://sequelize.org/docs/v6/category/advanced-association-concepts/
Eager Loadinghttps://sequelize.org/docs/v6/advanced-association-concepts/eager-loading/
Creating with Associationshttps://sequelize.org/docs/v6/advanced-association-concepts/creating-with-associations/
Advanced M:N Associationshttps://sequelize.org/docs/v6/advanced-association-concepts/advanced-many-to-many/
Association Scopeshttps://sequelize.org/docs/v6/advanced-association-concepts/association-scopes/
Polymorphic Associationshttps://sequelize.org/docs/v6/advanced-association-concepts/polymorphic-associations/
Other topicshttps://sequelize.org/docs/v6/category/other-topics/
Other Data Typeshttps://sequelize.org/docs/v6/other-topics/other-data-types/
Using sequelize in AWS Lambdahttps://sequelize.org/docs/v6/other-topics/aws-lambda/
Connection Poolhttps://sequelize.org/docs/v6/other-topics/connection-pool/
Constraints & Circularitieshttps://sequelize.org/docs/v6/other-topics/constraints-and-circularities/
Dialect-Specific Thingshttps://sequelize.org/docs/v6/other-topics/dialect-specific-things/
Extending Data Typeshttps://sequelize.org/docs/v6/other-topics/extending-data-types/
Hookshttps://sequelize.org/docs/v6/other-topics/hooks/
Indexeshttps://sequelize.org/docs/v6/other-topics/indexes/
Working with Legacy Tableshttps://sequelize.org/docs/v6/other-topics/legacy/
Legal Noticehttps://sequelize.org/docs/v6/other-topics/legal/
Migrationshttps://sequelize.org/docs/v6/other-topics/migrations/
Naming Strategieshttps://sequelize.org/docs/v6/other-topics/naming-strategies/
Optimistic Lockinghttps://sequelize.org/docs/v6/other-topics/optimistic-locking/
Query Interfacehttps://sequelize.org/docs/v6/other-topics/query-interface/
Read Replicationhttps://sequelize.org/docs/v6/other-topics/read-replication/
Resourceshttps://sequelize.org/docs/v6/other-topics/resources/
Scopeshttps://sequelize.org/docs/v6/other-topics/scopes/
Sub Querieshttps://sequelize.org/docs/v6/other-topics/sub-queries/
Transactionshttps://sequelize.org/docs/v6/other-topics/transactions/
TypeScripthttps://sequelize.org/docs/v6/other-topics/typescript/
Upgrade to v6https://sequelize.org/docs/v6/other-topics/upgrade/
Movedhttps://sequelize.org/docs/v6/category/moved/
https://sequelize.org/
Core Conceptshttps://sequelize.org/docs/v6/category/core-concepts/
One-To-Onehttps://en.wikipedia.org/wiki/One-to-one_%28data_model%29
One-To-Manyhttps://en.wikipedia.org/wiki/One-to-many_%28data_model%29
Many-To-Manyhttps://en.wikipedia.org/wiki/Many-to-many_%28data_model%29
One-To-Onehttps://en.wikipedia.org/wiki/One-to-one_%28data_model%29
One-To-Manyhttps://en.wikipedia.org/wiki/One-to-many_%28data_model%29
Many-To-Manyhttps://en.wikipedia.org/wiki/Many-to-many_%28data_model%29
https://sequelize.org/docs/v6/core-concepts/assocs/#defining-the-sequelize-associations
junction tablehttps://en.wikipedia.org/wiki/Associative_entity
https://sequelize.org/docs/v6/core-concepts/assocs/#creating-the-standard-relationships
Advanced Many-to-Many relationships guidehttps://sequelize.org/docs/v6/advanced-association-concepts/advanced-many-to-many/
https://sequelize.org/docs/v6/core-concepts/assocs/#one-to-one-relationships
https://sequelize.org/docs/v6/core-concepts/assocs/#philosophy
https://sequelize.org/docs/v6/core-concepts/assocs/#goal
https://sequelize.org/docs/v6/core-concepts/assocs/#implementation
https://sequelize.org/docs/v6/core-concepts/assocs/#options
https://sequelize.org/docs/v6/core-concepts/assocs/#ondelete-and-onupdate
https://sequelize.org/docs/v6/core-concepts/assocs/#customizing-the-foreign-key
https://sequelize.org/docs/v6/core-concepts/assocs/#mandatory-versus-optional-associations
https://sequelize.org/docs/v6/core-concepts/assocs/#one-to-many-relationships
https://sequelize.org/docs/v6/core-concepts/assocs/#philosophy-1
https://sequelize.org/docs/v6/core-concepts/assocs/#goal-1
https://sequelize.org/docs/v6/core-concepts/assocs/#implementation-1
https://sequelize.org/docs/v6/core-concepts/assocs/#options-1
https://sequelize.org/docs/v6/core-concepts/assocs/#many-to-many-relationships
https://sequelize.org/docs/v6/core-concepts/assocs/#philosophy-2
Junction Modelhttps://en.wikipedia.org/wiki/Associative_entity
https://sequelize.org/docs/v6/core-concepts/assocs/#goal-2
https://sequelize.org/docs/v6/core-concepts/assocs/#implementation-2
https://sequelize.org/docs/v6/core-concepts/assocs/#options-2
https://sequelize.org/docs/v6/core-concepts/assocs/#basics-of-queries-involving-associations
https://sequelize.org/docs/v6/core-concepts/assocs/#fetching-associations---eager-loading-vs-lazy-loading
https://sequelize.org/docs/v6/core-concepts/assocs/#lazy-loading-example
https://sequelize.org/docs/v6/core-concepts/assocs/#eager-loading-example
the dedicated guide on Eager Loadinghttps://sequelize.org/docs/v6/advanced-association-concepts/eager-loading/
https://sequelize.org/docs/v6/core-concepts/assocs/#creating-updating-and-deleting
special methods/mixinshttps://sequelize.org/docs/v6/core-concepts/assocs/#special-methodsmixins-added-to-instances
save() instance methodhttps://sequelize.org/api/v6/class/src/model.js~model#instance-method-save
https://sequelize.org/docs/v6/core-concepts/assocs/#association-aliases--custom-foreign-keys
https://sequelize.org/docs/v6/core-concepts/assocs/#recap-the-default-setup
https://sequelize.org/docs/v6/core-concepts/assocs/#providing-the-foreign-key-name-directly
https://sequelize.org/docs/v6/core-concepts/assocs/#defining-an-alias
Advanced Many-to-Many Associations guidehttps://sequelize.org/docs/v6/advanced-association-concepts/advanced-many-to-many/
https://sequelize.org/docs/v6/core-concepts/assocs/#doing-both-things
https://sequelize.org/docs/v6/core-concepts/assocs/#special-methodsmixins-added-to-instances
https://sequelize.org/docs/v6/core-concepts/assocs/#foohasonebar
https://sequelize.org/docs/v6/core-concepts/assocs/#foobelongstobar
https://sequelize.org/docs/v6/core-concepts/assocs/#foohasmanybar
https://sequelize.org/docs/v6/core-concepts/assocs/#foobelongstomanybar--through-baz-
https://sequelize.org/docs/v6/core-concepts/assocs/#note-method-names
https://sequelize.org/docs/v6/core-concepts/assocs/#why-associations-are-defined-in-pairs
https://sequelize.org/docs/v6/core-concepts/assocs/#multiple-associations-involving-the-same-models
https://sequelize.org/docs/v6/core-concepts/assocs/#creating-associations-referencing-a-field-which-is-not-the-primary-key
https://sequelize.org/docs/v6/core-concepts/assocs/#for-belongsto-relationships
https://sequelize.org/docs/v6/core-concepts/assocs/#for-hasone-and-hasmany-relationships
https://sequelize.org/docs/v6/core-concepts/assocs/#for-belongstomany-relationships
https://sequelize.org/docs/v6/core-concepts/assocs/#notes
Edit this pagehttps://github.com/sequelize/website/tree/main/versioned_docs/version-6.x.x/core-concepts/assocs.md
PreviousRaw Querieshttps://sequelize.org/docs/v6/core-concepts/raw-queries/
NextParanoidhttps://sequelize.org/docs/v6/core-concepts/paranoid/
Defining the Sequelize associationshttps://sequelize.org/docs/v6/core-concepts/assocs/#defining-the-sequelize-associations
Creating the standard relationshipshttps://sequelize.org/docs/v6/core-concepts/assocs/#creating-the-standard-relationships
One-To-One relationshipshttps://sequelize.org/docs/v6/core-concepts/assocs/#one-to-one-relationships
Philosophyhttps://sequelize.org/docs/v6/core-concepts/assocs/#philosophy
Goalhttps://sequelize.org/docs/v6/core-concepts/assocs/#goal
Implementationhttps://sequelize.org/docs/v6/core-concepts/assocs/#implementation
Optionshttps://sequelize.org/docs/v6/core-concepts/assocs/#options
One-To-Many relationshipshttps://sequelize.org/docs/v6/core-concepts/assocs/#one-to-many-relationships
Philosophyhttps://sequelize.org/docs/v6/core-concepts/assocs/#philosophy-1
Goalhttps://sequelize.org/docs/v6/core-concepts/assocs/#goal-1
Implementationhttps://sequelize.org/docs/v6/core-concepts/assocs/#implementation-1
Optionshttps://sequelize.org/docs/v6/core-concepts/assocs/#options-1
Many-To-Many relationshipshttps://sequelize.org/docs/v6/core-concepts/assocs/#many-to-many-relationships
Philosophyhttps://sequelize.org/docs/v6/core-concepts/assocs/#philosophy-2
Goalhttps://sequelize.org/docs/v6/core-concepts/assocs/#goal-2
Implementationhttps://sequelize.org/docs/v6/core-concepts/assocs/#implementation-2
Optionshttps://sequelize.org/docs/v6/core-concepts/assocs/#options-2
Basics of queries involving associationshttps://sequelize.org/docs/v6/core-concepts/assocs/#basics-of-queries-involving-associations
Fetching associations - Eager Loading vs Lazy Loadinghttps://sequelize.org/docs/v6/core-concepts/assocs/#fetching-associations---eager-loading-vs-lazy-loading
Creating, updating and deletinghttps://sequelize.org/docs/v6/core-concepts/assocs/#creating-updating-and-deleting
Association Aliases & Custom Foreign Keyshttps://sequelize.org/docs/v6/core-concepts/assocs/#association-aliases--custom-foreign-keys
Recap: the default setuphttps://sequelize.org/docs/v6/core-concepts/assocs/#recap-the-default-setup
Providing the foreign key name directlyhttps://sequelize.org/docs/v6/core-concepts/assocs/#providing-the-foreign-key-name-directly
Defining an Aliashttps://sequelize.org/docs/v6/core-concepts/assocs/#defining-an-alias
Doing both thingshttps://sequelize.org/docs/v6/core-concepts/assocs/#doing-both-things
Special methods/mixins added to instanceshttps://sequelize.org/docs/v6/core-concepts/assocs/#special-methodsmixins-added-to-instances
Foo.hasOne(Bar)https://sequelize.org/docs/v6/core-concepts/assocs/#foohasonebar
Foo.belongsTo(Bar)https://sequelize.org/docs/v6/core-concepts/assocs/#foobelongstobar
Foo.hasMany(Bar)https://sequelize.org/docs/v6/core-concepts/assocs/#foohasmanybar
Foo.belongsToMany(Bar, { through: Baz })https://sequelize.org/docs/v6/core-concepts/assocs/#foobelongstomanybar--through-baz-
Note: Method nameshttps://sequelize.org/docs/v6/core-concepts/assocs/#note-method-names
Why associations are defined in pairs?https://sequelize.org/docs/v6/core-concepts/assocs/#why-associations-are-defined-in-pairs
Multiple associations involving the same modelshttps://sequelize.org/docs/v6/core-concepts/assocs/#multiple-associations-involving-the-same-models
Creating associations referencing a field which is not the primary keyhttps://sequelize.org/docs/v6/core-concepts/assocs/#creating-associations-referencing-a-field-which-is-not-the-primary-key
For belongsTo relationshipshttps://sequelize.org/docs/v6/core-concepts/assocs/#for-belongsto-relationships
For hasOne and hasMany relationshipshttps://sequelize.org/docs/v6/core-concepts/assocs/#for-hasone-and-hasmany-relationships
For belongsToMany relationshipshttps://sequelize.org/docs/v6/core-concepts/assocs/#for-belongstomany-relationships
Noteshttps://sequelize.org/docs/v6/core-concepts/assocs/#notes
Guideshttps://sequelize.org/docs/v6/
Version Policyhttps://sequelize.org/releases/
Securityhttps://github.com/sequelize/sequelize/blob/main/SECURITY.md
Changeloghttps://github.com/sequelize/sequelize/releases
Legalhttps://sequelize.org/legal/
Stack Overflowhttps://stackoverflow.com/questions/tagged/sequelize.js
Slackhttps://sequelize.org/slack
Twitterhttps://twitter.com/SequelizeJS
GitHubhttps://github.com/sequelize/sequelize
OpenCollectivehttps://opencollective.com/sequelize
powered by Netlifyhttps://www.netlify.com

Viewport: width=device-width,initial-scale=1


URLs of crawlers that visited me.