{"id":326138,"date":"2021-07-08T09:00:46","date_gmt":"2021-07-08T09:00:46","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=326138"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=326138","title":{"rendered":"\u0418\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0421\u0423\u0411\u0414 \u0431\u0435\u0437 SQL \u0434\u043b\u044f Node.js \u0438\u043b\u0438 \u0412\u0441\u0435, \u0447\u0442\u043e \u0432\u044b \u0445\u043e\u0442\u0435\u043b\u0438 \u0437\u043d\u0430\u0442\u044c \u043e Sequelize. \u0427\u0430\u0441\u0442\u044c 2"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/gu\/0h\/ok\/gu0hokcjqofxktdkr7hkerc1zxm.jpeg\">  <\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e <code>Sequelize<\/code>.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/sequelize.org\/master\/\"><code>Sequelize<\/code><\/a> \u2014 \u044d\u0442\u043e <a href=\"https:\/\/ru.wikipedia.org\/wiki\/ORM\"><code>ORM<\/code><\/a> (Object-Relational Mapping \u2014 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435) \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A1%D0%B8%D1%81%D1%82%D0%B5%D0%BC%D0%B0_%D1%83%D0%BF%D1%80%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F_%D0%B1%D0%B0%D0%B7%D0%B0%D0%BC%D0%B8_%D0%B4%D0%B0%D0%BD%D0%BD%D1%8B%D1%85\">\u0421\u0423\u0411\u0414<\/a> (\u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f (\u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u044b\u043c\u0438) \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, Relational Database Management System, RDBMS), \u043a\u0430\u043a <code>Postgres<\/code>, <code>MySQL<\/code>, <code>MariaDB<\/code>, <code>SQLite<\/code> \u0438 <code>MSSQL<\/code>. \u042d\u0442\u043e \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f <code>ORM<\/code> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0434\u0430\u043b\u0435\u0435 \u2014 \u0411\u0414), \u043d\u043e, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043e\u0434\u043d\u0430 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0445 \u0438, \u0447\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, &quot;battle tested&quot; (\u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c).<\/p>\n<p>  <\/p>\n<p><code>ORM<\/code> \u0445\u043e\u0440\u043e\u0448\u0438 \u0442\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0411\u0414 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (<code>JavaScript<\/code>), \u0442.\u0435. \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u043e\u0432 (<code>SQL<\/code>). \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0411\u0414 \u043b\u0435\u0433\u0447\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>SQL<\/code> (\u0438\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e c \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0433\u043e). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u0434 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u0431\u0435\u0433\u043b\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043d\u0430 <code>SQL<\/code>. \u0412\u043e\u0442 <a href=\"https:\/\/habr.com\/ru\/company\/macloud\/blog\/564390\/\">\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430<\/a>.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0438\u0437 3 \u0447\u0430\u0441\u0442\u0435\u0439 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0445 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f\u0445 (\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u0445 \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438), &quot;\u043f\u0430\u0440\u0430\u043d\u043e\u0438\u043a\u0435&quot;, \u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u043e\u0439 \u0438 \u043b\u0435\u043d\u0438\u0432\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e \u043c\u043d\u043e\u0433\u043e\u043c \u0434\u0440\u0443\u0433\u043e\u043c.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 <a href=\"https:\/\/habr.com\/ru\/company\/macloud\/blog\/565062\/\">\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u0435\u0440\u0432\u0443\u044e \u0447\u0430\u0441\u0442\u044c<\/a>.<\/p>\n<p>  <\/p>\n<p>\u042f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0431\u044b\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u043c (\u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0431\u0435\u0437 \u0443\u0449\u0435\u0440\u0431\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430). \u042f \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0438\u0437\u043b\u0430\u0433\u0430\u0442\u044c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u044f\u0437\u044b\u043a\u043e\u043c. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c\u044b\u0445 \u0432 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435, \u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u044b \u0438\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"soderzhanie\">\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<ul>\n<li><a href=\"#%D0%B0%D1%81%D1%81%D0%BE%D1%86%D0%B8%D0%B0%D1%86%D0%B8%D0%B8\">\u0410\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438<\/a><\/li>\n<li><a href=\"#%D0%BF%D0%B0%D1%80%D0%B0%D0%BD%D0%BE%D0%B8%D0%BA\">&quot;\u041f\u0430\u0440\u0430\u043d\u043e\u0438\u043a&quot;<\/a><\/li>\n<li><a href=\"#%D0%BD%D0%B5%D1%82%D0%B5%D1%80%D0%BF%D0%B5%D0%BB%D0%B8%D0%B2%D0%B0%D1%8F-%D0%B7%D0%B0%D0%B3%D1%80%D1%83%D0%B7%D0%BA%D0%B0\">\u041d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430<\/a><\/li>\n<li><a href=\"#%D1%81%D0%BE%D0%B7%D0%B4%D0%B0%D0%BD%D0%B8%D0%B5-%D1%8D%D0%BA%D0%B7%D0%B5%D0%BC%D0%BF%D0%BB%D1%8F%D1%80%D0%BE%D0%B2-%D1%81-%D0%BF%D0%BE%D0%BC%D0%BE%D1%89%D1%8C%D1%8E-%D0%B0%D1%81%D1%81%D0%BE%D1%86%D0%B8%D0%B0%D1%86%D0%B8%D0%B9\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u0441 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f\u043c\u0438<\/a><\/li>\n<li><a href=\"#%D0%BF%D1%80%D0%BE%D0%B4%D0%B2%D0%B8%D0%BD%D1%83%D1%82%D1%8B%D0%B5-%D0%B0%D1%81%D1%81%D0%BE%D1%86%D0%B8%D0%B0%D1%86%D0%B8%D0%B8-mn\">\u041f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0435 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 M:N<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"associacii\">\u0410\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438<\/h2>\n<p>  <\/p>\n<p><code>Sequelize<\/code> \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438: \u043e\u0434\u0438\u043d-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443 (One-To-One), \u043e\u0434\u0438\u043d-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c (One-To-Many), \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c (Many-To-Many).<\/p>\n<p>  <\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 4 \u0442\u0438\u043f\u0430 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>HasOne<\/code><\/li>\n<li><code>BelongsTo<\/code><\/li>\n<li><code>HasMany<\/code><\/li>\n<li><code>BelongsToMany<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438<\/strong><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442\u0441\u044f 2 \u043c\u043e\u0434\u0435\u043b\u0438, <code>A<\/code> \u0438 <code>B<\/code>. \u0412\u043e\u0442 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0441\u0432\u044f\u0437\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const A = sequelize.define('A' \/* ... *\/) const B = sequelize.define('B' \/* ... *\/)  A.hasOne(B) A.belongsTo(B) A.hasMany(B) A.belongsToMany(B)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438 (\u0434\u043b\u044f \u043f\u0435\u0440\u0432\u044b\u0445 \u0442\u0440\u0435\u0445 \u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c, \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u2014 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c). \u0412 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>through<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">A.hasOne(B, {   \/* \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 *\/ }) A.belongsTo(B, {   \/* \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 *\/ }) A.hasMany(B, {   \/* \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 *\/ }) A.belongsToMany(B, { through: 'C' \/* \u0434\u0440\u0443\u0433\u0438\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 *\/ })<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0440\u044f\u0434\u043e\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 <code>A<\/code> \u2014 \u044d\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a (source), \u0430 <code>B<\/code> \u2014 \u044d\u0442\u043e \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c (target). \u0417\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u044d\u0442\u0438 \u0442\u0435\u0440\u043c\u0438\u043d\u044b.<\/p>\n<p>  <\/p>\n<p><code>A.hasOne(B)<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u0435\u0436\u0434\u0443 <code>A<\/code> \u0438 <code>B<\/code> \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043e\u0434\u0438\u043d-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447 (foreign key) \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 (<code>B<\/code>).<\/p>\n<p>  <\/p>\n<p><code>A.belongsTo(B)<\/code> \u2014 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043e\u0434\u0438\u043d-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443, \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0435 (<code>A<\/code>).<\/p>\n<p>  <\/p>\n<p><code>A.hasMany(B)<\/code> \u2014 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043e\u0434\u0438\u043d-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c, \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 (<code>B<\/code>).<\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 <code>Sequelize<\/code> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438 (\u043f\u0440\u0438 \u0438\u0445 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438) \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 (\u0442\u0430\u0431\u043b\u0438\u0446\u044b).<\/p>\n<p>  <\/p>\n<p><code>A.belongsToMany(B, { through: 'C' })<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u0435\u0436\u0434\u0443 <code>A<\/code> \u0438 <code>B<\/code> \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 <code>C<\/code> \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0432 \u0440\u043e\u043b\u0438 \u0441\u0432\u044f\u0437\u0443\u044e\u0449\u0435\u0433\u043e \u0437\u0432\u0435\u043d\u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>aId<\/code> \u0438 <code>bId<\/code>). <code>Sequelize<\/code> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c <code>C<\/code> \u043f\u0440\u0438 \u0435\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044f \u0432 \u043d\u0435\u0439 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043a\u043b\u044e\u0447\u0438.<\/p>\n<p>  <\/p>\n<p><strong>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439<\/strong><\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439 \u043e\u0434\u0438\u043d-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f <code>hasOne()<\/code> \u0438 <code>belongsTo()<\/code><\/li>\n<li>\u0434\u043b\u044f \u043e\u0434\u0438\u043d-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u2014 <code>hasMany()<\/code> \u0438 <code>belongsTo()<\/code><\/li>\n<li>\u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u2014 \u0434\u0432\u0430 <code>belongsToMany()<\/code>. <em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/em>, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f &quot;\u0441\u0443\u043f\u0435\u0440 \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c&quot;, \u0433\u0434\u0435 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>6<\/code> \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u041e\u0434\u0438\u043d-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443<\/strong><\/p>\n<p>  <\/p>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/em>: \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c, \u0432 \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447, \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a\u0430\u044f \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446 \u043c\u043e\u0436\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0437 \u0434\u0440\u0443\u0433\u043e\u0439.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0434\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, <code>Foo<\/code> \u0438 <code>Bar<\/code>. \u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043e\u0434\u0438\u043d-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b <code>Bar<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b\u0430 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>fooId<\/code>. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Foo.hasOne(Bar) Bar.belongsTo(Foo)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0439 \u0432\u044b\u0437\u043e\u0432 <code>Bar.sync()<\/code> \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0432 \u0411\u0414 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">CREATE TABLE IF NOT EXISTS &quot;foos&quot; (   \/* ... *\/ ); CREATE TABLE IF NOT EXISTS &quot;bars&quot; (   \/* ... *\/   &quot;fooId&quot; INTEGER REFERENCES &quot;foos&quot; (&quot;id&quot;) ON DELETE SET NULL ON UPDATE CASCADE   \/* ... *\/ );<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Foo.hasOne(Bar, {   onDelete: 'RESTRICT',   onUpdate: 'RESTRICT' }) Bar.belongsTo(Foo)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u043c\u0438 \u0437\u0434\u0435\u0441\u044c \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f: <code>RESTRICT<\/code>, <code>CASCADE<\/code>, <code>NO ACTION<\/code>, <code>SET DEFAULT<\/code> \u0438 <code>SET NULL<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>fooId<\/code>, \u043c\u043e\u0436\u043d\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u041f\u0440\u0438\u0447\u0435\u043c, \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u043a \u0432 <code>hasOne()<\/code>, \u0442\u0430\u043a \u0438 \u0432 <code>belongsTo()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">\/\/ 1 Foo.hasOne(Bar, {   foreignKey: 'myFooId' }) Bar.belongsTo(Foo)  \/\/ 2 Foo.hasOne(Bar, {   foreignKey: {     name: 'myFooId'   } }) Bar.belongsTo(Foo)  \/\/ 3 Foo.hasOne(Bar) Bar.belongsTo(Foo, {   foreignKey: 'myFooId' })  \/\/ 4 Foo.hasOne(Bar) Bar.belongsTo(Foo, {   foreignKey: {     name: 'myFooId'   } })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0435\u0433\u043e \u0442\u0438\u043f, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0438 \u0442.\u0434. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0438\u043f\u0430 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>DataTypes.UUID<\/code> \u0432\u043c\u0435\u0441\u0442\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0433\u043e <code>INTEGER<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Foo.hasOne(Bar, {   foreignKey: {     type: DataTypes.UUID   } }) Bar.belongsTo(Foo)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0439, \u0442.\u0435. <code>fooId<\/code> \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>null<\/code> \u2014 <code>Bar<\/code> \u043c\u043e\u0436\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0437 <code>Foo<\/code>. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0442\u0430\u043a\u043e\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Foo.hasOne(Bar, {   foreignKey: {     allowNull: false   } })<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u041e\u0434\u0438\u043d-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c<\/strong><\/p>\n<p>  <\/p>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/em>: \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u0442\u043e\u043c, \u0432 \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u044e\u0447 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0434\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, <code>Team<\/code> \u0438 <code>Player<\/code>, \u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043e\u0434\u0438\u043d-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c: \u0432 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0433\u0440\u043e\u043a\u043e\u0432, \u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0433\u0440\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043a \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Team.hasMany(Player) Player.belongsTo(Team)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u0411\u0414 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">CREATE TABLE IF NOT EXISTS &quot;Teams&quot; (   \/* ... *\/ ); CREATE TABLE IF NOT EXISTS &quot;Players&quot; (   \/* ... *\/   &quot;TeamId&quot; INTEGER REFERENCES &quot;Teams&quot; (&quot;id&quot;) ON DELETE SET NULL ON UPDATE CASCADE,   \/* ... *\/ );<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c\u0438 \u043e\u0434\u0438\u043d-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443, \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u0443\u044e \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Team.hasMany(Player, {   foreignKey: 'clubId' }) Player.belongsTo(Team)<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u041c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c<\/strong><\/p>\n<p>  <\/p>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/em>: \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043f\u0435\u0440\u0432\u044b\u0445 \u0434\u0432\u0443\u0445 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439, \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u043d\u0438 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f &quot;\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430&quot; (junction, join, through table).<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0434\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, <code>Movie<\/code> (\u0444\u0438\u043b\u044c\u043c) \u0438 <code>Actor<\/code> (\u0430\u043a\u0442\u0435\u0440), \u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c: \u0430\u043a\u0442\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0443\u0447\u0430\u0441\u0442\u0438\u0435 \u0432 \u0441\u044a\u0435\u043c\u043a\u0430\u0445 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0444\u0438\u043b\u044c\u043c\u043e\u0432, \u0430 \u0432 \u0444\u0438\u043b\u044c\u043c\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u043a\u0442\u0435\u0440\u043e\u0432. \u0421\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f <code>ActorMovies<\/code> \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438 <code>actorId<\/code> \u0438 <code>movieId<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Movie = sequelize.define('Movie', { name: DataTypes.STRING }) const Actor = sequelize.define('Actor', { name: DataTypes.STRING }) Movie.belongsToMany(Actor, { through: 'ActorMovies' }) Actor.belongsToMany(Movie, { through: 'ActorMovies' })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 <code>postgres<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">CREATE TABLE IF NOT EXISTS &quot;ActorMovies&quot; (   &quot;createdAt&quot; TIMESTAMP WITH TIME ZONE NOT NULL,   &quot;updatedAt&quot; TIMESTAMP WITH TIME ZONE NOT NULL,   &quot;MovieId&quot; INTEGER REFERENCES &quot;Movies&quot; (&quot;id&quot;) ON DELETE CASCADE ON UPDATE CASCADE,   &quot;ActorId&quot; INTEGER REFERENCES &quot;Actors&quot; (&quot;id&quot;) ON DELETE CASCADE ON UPDATE CASCADE,   PRIMARY KEY (&quot;MovieId&quot;,&quot;ActorId&quot;) );<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u043d\u0435\u0435, <code>Sequelize<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u041d\u043e \u043c\u044b \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Movie = sequelize.define('Movie', { name: DataTypes.STRING }) const Actor = sequelize.define('Actor', { name: DataTypes.STRING }) const ActorMovies = sequelize.define('ActorMovies', {   MovieId: {     type: DataTypes.INTEGER,     references: {       model: Movie, \/\/ \u0438\u043b\u0438 'Movies'       key: 'id'     }   },   ActorId: {     type: DataTypes.INTEGER,     references: {       model: Actor, \/\/ \u0438\u043b\u0438 'Actors'       key: 'id'     }   } }) Movie.belongsToMany(Actor, { through: ActorMovies }) Actor.belongsToMany(Movie, { through: ActorMovies })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u0411\u0414 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">CREATE TABLE IF NOT EXISTS &quot;ActorMovies&quot; (   &quot;MovieId&quot; INTEGER NOT NULL REFERENCES &quot;Movies&quot; (&quot;id&quot;) ON DELETE RESTRICT ON UPDATE CASCADE,   &quot;ActorId&quot; INTEGER NOT NULL REFERENCES &quot;Actors&quot; (&quot;id&quot;) ON DELETE RESTRICT ON UPDATE CASCADE,   &quot;createdAt&quot; TIMESTAMP WITH TIME ZONE NOT NULL,   &quot;updatedAt&quot; TIMESTAMP WITH TIME ZONE NOT NULL,   UNIQUE (&quot;MovieId&quot;, &quot;ActorId&quot;),     -- Note: Sequelize generated this UNIQUE constraint but   PRIMARY KEY (&quot;MovieId&quot;,&quot;ActorId&quot;)  -- it is irrelevant since it's also a PRIMARY KEY );<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0445 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438<\/strong><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0434\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, <code>Ship<\/code> (\u043a\u043e\u0440\u0430\u0431\u043b\u044c) \u0438 <code>Captain<\/code> (\u043a\u0430\u043f\u0438\u0442\u0430\u043d). \u041c\u0435\u0436\u0434\u0443 \u044d\u0442\u0438\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043e\u0434\u0438\u043d-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443. \u0412\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438 \u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>null<\/code>. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u043e\u0440\u0430\u0431\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0437 \u043a\u0430\u043f\u0438\u0442\u0430\u043d\u0430, \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Ship = sequelize.define(   'Ship',   {     name: DataTypes.STRING,     crewCapacity: DataTypes.INTEGER,     amountOfSails: DataTypes.INTEGER   },   { timestamps: false } ) const Captain = sequelize.define(   'Captain',   {     name: DataTypes.STRING,     skillLevel: {       type: DataTypes.INTEGER,       validate: { min: 1, max: 10 }     }   },   { timestamps: false } ) Captain.hasOne(Ship) Ship.belongsTo(Captain)<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u041d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430<\/strong><\/p>\n<p>  <\/p>\n<p>&quot;\u041b\u0435\u043d\u0438\u0432\u0430\u044f&quot; (lazy) \u0438\u043b\u0438 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 (\u0442.\u0435. \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b) \u043f\u043e \u043c\u0435\u0440\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u0430 &quot;\u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u0430\u044f&quot; (eager) \u0438\u043b\u0438 \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u043b\u0435\u043d\u0438\u0432\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const awesomeCaptain = await Captain.findOne({   where: {     name: 'Jack Sparrow'   } }) \/\/ \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441 \u043a\u0430\u043f\u0438\u0442\u0430\u043d\u043e\u043c \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0435\u0433\u043e \u043a\u043e\u0440\u0430\u0431\u043b\u044c const hisShip = await awesomeCaptain.getShip() \/\/ \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441 \u043a\u043e\u0440\u0430\u0431\u043b\u0435\u043c<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0434\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u2014 \u043a\u043e\u0440\u0430\u0431\u043b\u044c \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0438 \u043f\u0430\u043c\u044f\u0442\u044c. <em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/em>: \u043c\u0435\u0442\u043e\u0434 <code>getShip()<\/code> \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b (\u0441\u043c. \u043d\u0438\u0436\u0435).<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const awesomeCaptaint = await Captain.findOne({   where: {     name: 'Jack Sparrow'   },   \/\/ \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u043e\u0440\u0430\u0431\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043f\u0438\u0442\u0430\u043d   include: Ship })<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435, \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439<\/strong><\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f, \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Bar.create({   name: 'Bar',   fooId: 3 }) \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c `Bar`, \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0443\u044e `Foo` c `id` = 3<\/code><\/pre>\n<p>  <\/p>\n<p>\u0442\u0430\u043a \u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b\/\u043c\u0438\u043a\u0441\u0438\u043d\u044b (\u043c\u0438\u043a\u0448\u0438\u043d\u044b, \u043f\u0440\u0438\u043c\u0435\u0441\u0438, mixins) (\u0441\u043c. \u043d\u0438\u0436\u0435).<\/p>\n<p>  <\/p>\n<p><strong>\u0421\u0438\u043d\u043e\u043d\u0438\u043c\u044b \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438<\/strong><\/p>\n<p>  <\/p>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043a\u043e\u0440\u0430\u0431\u043b\u044f\u043c\u0438 \u0438 \u043a\u0430\u043f\u0438\u0442\u0430\u043d\u0430\u043c\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Ship = sequelize.define(   'Ship',   { name: DataTypes.STRING },   { timestamps: false } ) const Captain = sequelize.define(   'Captain',   { name: DataTypes.STRING },   { timestamps: false } )<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b\u0437\u043e\u0432 <code>Ship.belongsTo(Captain)<\/code> \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0438 &quot;\u0433\u0435\u0442\u0442\u0435\u0440\u043e\u0432&quot;:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Ship.belongsTo(Captain)  console.log((await Ship.findAll({ include: Captain })).toJSON()) \/\/ \u0438\u043b\u0438 console.log((await Ship.findAll({ include: 'Captain' })).toJSON())  const ship = await Ship.findOne() console.log((await ship.getCaptain()).toJSON())<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u043f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Ship.belongsTo(Captain, { foreignKey: 'bossId' })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0432 \u0432\u0438\u0434\u0435 \u0441\u0438\u043d\u043e\u043d\u0438\u043c\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Ship.belongsTo(Captain, { as: 'leader' })  \/\/ \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0431\u0440\u043e\u0448\u0435\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 console.log((await Ship.findAll({ include: Captain })).toJSON()) \/\/ \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043d\u043e\u043d\u0438\u043c console.log((await Ship.findAll({ include: 'leader' })).toJSON())<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0438\u043d\u043e\u043d\u0438\u043c\u044b \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u043e\u0434\u043d\u0438\u043c\u0438 \u0438 \u0442\u0435\u043c\u0438 \u0436\u0435 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u0438 <code>Mail<\/code> \u0438 <code>Person<\/code>, \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0438\u0445 \u0434\u0432\u0430\u0436\u0434\u044b \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f <code>sender<\/code> (\u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044f) \u0438 <code>receiver<\/code> (\u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044f) \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b. \u0415\u0441\u043b\u0438 \u043c\u044b \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c, \u0442\u043e \u0432\u044b\u0437\u043e\u0432 <code>mail.getPerson()<\/code> \u0431\u0443\u0434\u0435\u0442 \u0434\u0432\u0443\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u044b\u043c. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0441\u0438\u043d\u043e\u043d\u0438\u043c\u0430\u043c \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430: <code>mail.getSender()<\/code> \u0438 <code>mail.getReceiver()<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u0441\u0438\u043d\u043e\u043d\u0438\u043c\u043e\u0432 \u0434\u043b\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 <code>hasOne()<\/code> \u0438\u043b\u0438 <code>belongsTo()<\/code>, \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443 (\u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e), \u0430 \u0434\u043b\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 <code>hasMany()<\/code> \u0438\u043b\u0438 <code>belongsToMany()<\/code> \u2014 \u043f\u043b\u044e\u0440\u0430\u043b\u044c\u043d\u0443\u044e (\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e).<\/p>\n<p>  <\/p>\n<p>\u041d\u0438\u0447\u0442\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u043d\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043a\u043b\u044e\u0447\u0435\u0439 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Ship.belongsTo(Captain, { as: 'leader', foreignKey: 'bossId' })<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0421\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b\/\u043c\u0438\u043a\u0441\u0438\u043d\u044b<\/strong><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438, \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u044d\u0442\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438. \u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u0442\u0438\u043f\u0430 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0434\u0432\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, <code>Foo<\/code> \u0438 <code>Bar<\/code>.<\/p>\n<p>  <\/p>\n<p><strong><code>Foo.hasOne(Bar)<\/code><\/strong><\/p>\n<p>  <\/p>\n<ul>\n<li><code>foo.getBar()<\/code><\/li>\n<li><code>foo.setBar()<\/code><\/li>\n<li><code>foo.createBar()<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"javascript\">const foo = await Foo.create({ name: 'foo' }) const bar = await Bar.create({ name: 'bar' }) const bar2 = await Bar.create({ name: 'another bar' })  console.log(await foo.getBar()) \/\/ null  await foo.setBar(bar) console.log(await foo.getBar().name) \/\/ bar  await foo.createBar({ name: 'and another bar' }) console.log(await foo.getBar().name) \/\/ and another bar  await foo.setBar(null) \/\/ \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044e console.log(await foo.getBar()) \/\/ null<\/code><\/pre>\n<p>  <\/p>\n<p><strong><code>Foo.belongsTo(Bar)<\/code><\/strong><\/p>\n<p>  <\/p>\n<ul>\n<li><code>foo.getBar()<\/code><\/li>\n<li><code>foo.setBar()<\/code><\/li>\n<li><code>foo.createBar()<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong><code>Foo.hasMany<\/code><\/strong><\/p>\n<p>  <\/p>\n<ul>\n<li><code>foo.getBars()<\/code><\/li>\n<li><code>foo.countBars()<\/code><\/li>\n<li><code>foo.hasBar()<\/code><\/li>\n<li><code>foo.hasBars()<\/code><\/li>\n<li><code>foo.setBars()<\/code><\/li>\n<li><code>foo.addBar()<\/code><\/li>\n<li><code>foo.addBars()<\/code><\/li>\n<li><code>foo.removeBar()<\/code><\/li>\n<li><code>foo.removeBars()<\/code><\/li>\n<li><code>foo.createBar()<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"javascript\">const foo = await Foo.create({ name: 'foo' }) const bar = await Bar.create({ name: 'bar' }) const bar2 = await Bar.create({ name: 'another bar' })  console.log(await foo.getBars()) \/\/ [] console.log(await foo.countBars()) \/\/ 0 console.log(await foo.hasBar(bar)) \/\/ false  await foo.addBars([bar, bar2]) console.log(await foo.countBars) \/\/ 2  await foo.addBar(bar) console.log(await foo.countBars()) \/\/ 2 console.log(await foo.hasBar(bar)) \/\/ true  await foo.removeBar(bar2) console.log(await foo.countBars()) \/\/ 1  await foo.createBar({ name: 'and another bar' }) console.log(await foo.countBars()) \/\/ 2  await foo.setBars([]) console.log(await foo.countBars()) \/\/ 0<\/code><\/pre>\n<p>  <\/p>\n<p>\u0413\u0435\u0442\u0442\u0435\u0440\u044b \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u0442\u0430\u043a\u0438\u0435 \u0436\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438, \u0447\u0442\u043e \u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b (\u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <code>findAll()<\/code>):<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const easyTasks = await project.getTasks({   where: {     difficulty: {       [Op.lte]: 5     }   } })  const taskTitles = (   await project.getTasks({     attributes: ['title'],     raw: true   }) ).map((task) =&gt; task.title)<\/code><\/pre>\n<p>  <\/p>\n<p><strong><code>Foo.belongsToMany(Bar, { through: Baz })<\/code><\/strong><\/p>\n<p>  <\/p>\n<ul>\n<li><code>foo.getBars()<\/code><\/li>\n<li><code>foo.countBars()<\/code><\/li>\n<li><code>foo.hasBar()<\/code><\/li>\n<li><code>foo.hasBars()<\/code><\/li>\n<li><code>foo.setBars()<\/code><\/li>\n<li><code>foo.addBar()<\/code><\/li>\n<li><code>foo.addBars()<\/code><\/li>\n<li><code>foo.removeBar()<\/code><\/li>\n<li><code>foo.removeBars()<\/code><\/li>\n<li><code>foo.createBar()<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0438\u043d\u043e\u043d\u0438\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Task.hasOne(User, { as: 'Author' })<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li><code>task.getAuthor()<\/code><\/li>\n<li><code>task.setAuthor()<\/code><\/li>\n<li><code>task.createAuthor()<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/em>: \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u043e\u0442\u043c\u0435\u0447\u0435\u043d\u043e \u0440\u0430\u043d\u0435\u0435, \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u043f\u0430\u0440\u0435. \u042d\u0442\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u043e\u0431\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u043d\u0430\u0442\u044c \u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0438 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438.<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044e <code>Foo.hasOne(Bar)<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"javascript\">\/\/ \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c await Foo.findOne({ include: Bar })  \/\/ \u0430 \u0437\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0431\u0440\u043e\u0448\u0435\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 await Bar.findOne({ include: Foo })<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u0435\u0441\u043b\u0438 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043f\u0430\u0440\u0443 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439, \u0442\u043e \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"javascript\">Bar.belongsTo(Foo)  \/\/ \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 await Foo.findOne({ include: Bar })  \/\/ \u0438 \u044d\u0442\u043e \u0442\u043e\u0436\u0435 await Bar.findOne({ include: Foo })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0438\u043d\u043e\u043d\u0438\u043c\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u043e\u0434\u043d\u0438\u043c\u0438 \u0438 \u0442\u0435\u043c\u0438 \u0436\u0435 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Team.hasOne(Game, { as: 'HomeTeam', foreignKey: 'homeTeamId' }) Team.hasOne(Game, { as: 'AwayTeam', foreignKey: 'awayTeamId' }) Game.belongsTo(Team)<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043e\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u043c\u0438 \u043a\u043b\u044e\u0447\u0430\u043c\u0438<\/strong><\/p>\n<p>  <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043a\u043b\u044e\u0447\u0435\u0439 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043a\u043b\u044e\u0447\u0438, \u043d\u043e \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u043b\u044f. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a \u043f\u043e\u043b\u044e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u043c\u0443 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u044d\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u043c\u044b\u0441\u043b\u0430.<\/p>\n<p>  <\/p>\n<p><strong><code>belongsTo()<\/code><\/strong><\/p>\n<p>  <\/p>\n<p>\u0410\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f <code>A.belongsTo(B)<\/code> \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0435 (<code>A<\/code>).<\/p>\n<p>  <\/p>\n<p>\u0421\u043d\u043e\u0432\u0430 \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0441 \u043a\u043e\u0440\u0430\u0431\u043b\u044f\u043c\u0438 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438\u043c\u0435\u043d \u043a\u0430\u043f\u0438\u0442\u0430\u043d\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Ship = sequelize.define(   'Ship',   { name: DataTypes.STRING },   { timestamps: false } ) const Captain = sequelize.define(   'Captain',   {     name: { type: DataTypes.STRING, unique: true }   },   { timestamp: false } )<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0432\u043c\u0435\u0441\u0442\u043e <code>captainId<\/code> \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>captainName<\/code>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 <code>targetKey<\/code> \u0438 <code>foreignKey<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Ship.belongsTo(Captain, { targetKey: 'name', foreignKey: 'captainName' })<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">await Captain.create({ name: 'Jack Sparrow' }) const ship = Ship.create({ name: 'Black Pearl', captainName: 'Jack Sparrow' }) console.log((await ship.getCaptain()).name) \/\/ Jack Sparrow<\/code><\/pre>\n<p>  <\/p>\n<p><strong><code>hasOne()<\/code> \u0438 <code>hasMany()<\/code><\/strong><\/p>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043c\u0435\u0441\u0442\u043e <code>targetKey<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 <code>sourceKey<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Foo = sequelize.define(   'foo',   {     name: {       type: DataTypes.STRING,       unique: true     }   },   {     timestamps: false   } ) const Bar = sequelize.define(   'bar',   {     title: {       type: DataTypes.STRING,       unique: true     }   },   {     timestamps: false   } ) const Baz = sequelize.define(   'baz',   {     summary: DataTypes.STRING   },   {     timestamps: false   } ) Foo.hasOne(Bar, { sourceKey: 'name', foreignKey: 'fooName' }) Bar.hasMany(Baz, { sourceKey: 'title', foreignKey: 'barTitle' })  await Bar.setFoo('\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u044f `Foo`') await Bar.addBar('\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u044f `Bar`')<\/code><\/pre>\n<p>  <\/p>\n<p><strong><code>belongsToMany()<\/code><\/strong><\/p>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0432\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043a\u043b\u044e\u0447\u0430 \u0432 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Foo = sequelize.define(   'foo',   {     name: { type: DataTypes.STRING, unique: true }   },   { timestamps: false } ) const Bar = sequelize.define(   'bar',   {     title: { type: DataTypes.STRING, unique: true }   },   { timestamps: false } )<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 4 \u0448\u0430\u0433\u043e\u0432:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043c\u0435\u0436\u0434\u0443 <code>Foo<\/code> \u0438 <code>Bar<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0445 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"javascript\">Foo.belongsToMany(Bar, { through: 'foo_bar' })<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0434\u043b\u044f <code>Foo<\/code> \u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0434\u043b\u044f <code>Bar<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"javascript\">Foo.belongsToMany(Bar, { through: 'foo_bar', targetKey: 'title' })<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0434\u043b\u044f <code>Foo<\/code> \u0438 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0434\u043b\u044f <code>Bar<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"javascript\">Foo.belongsToMany(Bar, { through: 'foo_bar', sourceKey: 'name' })<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439 \u0434\u043b\u044f \u043e\u0431\u0435\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"javascript\">Foo.belongsToMany(Bar, {   through: 'foo_bar',   sourceKey: 'name',   targetKey: 'title' })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0449\u0435 \u0440\u0430\u0437 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>A.belongsTo(B)<\/code> \u2014 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u043c\u043e\u0434\u0435\u043b\u0438-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0435 (<code>A<\/code>), \u0441\u0441\u044b\u043b\u043a\u0430 (<code>targetKey<\/code>) \u2014 \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 (<code>B<\/code>)<\/li>\n<li><code>A.hasOne(B)<\/code> \u0438 <code>A.hasMany(B)<\/code> \u2014 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 (<code>B<\/code>), \u0430 \u0441\u0441\u044b\u043b\u043a\u0430 (<code>sourceKey<\/code>) \u2014 \u0432 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0435 (<code>A<\/code>)<\/li>\n<li><code>A.belongsToMany(B)<\/code> \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0438 \u0434\u043b\u044f <code>sourceKey<\/code> \u0438 <code>targetKey<\/code>, <code>sourceKey<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u043e\u043b\u044e \u0432 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0435 (<code>A<\/code>), <code>targetKey<\/code> \u2014 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u043e\u043b\u044e \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 (<code>B<\/code>)<\/li>\n<\/ul>\n<p>   <b><a href=\"#\">\u21a5 \u041d\u0430\u0432\u0435\u0440\u0445<\/a><\/b><\/p>\n<h2 id=\"paranoik\">&quot;\u041f\u0430\u0440\u0430\u043d\u043e\u0438\u043a&quot;<\/h2>\n<p>  <\/p>\n<p><code>Sequelize<\/code> \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0445 &quot;\u043f\u0430\u0440\u0430\u043d\u043e\u0438\u0434\u0430\u043b\u044c\u043d\u044b\u0445&quot; (paranoid) \u0442\u0430\u0431\u043b\u0438\u0446. \u0418\u0437 \u0442\u0430\u043a\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e-\u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u043d\u0435 \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e, \u0432 \u043d\u0438\u0445 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0430 <code>deletedAt<\/code> \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432 \u0442\u0430\u043a\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043c\u044f\u0433\u043a\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 (soft-deletion).<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043d\u043e\u0438\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 <code>paranoid: true<\/code>. <em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/em>: \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0430\u043a\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0444\u0438\u043a\u0441\u0430\u0446\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u043d\u0438\u0445 \u043d\u0435\u043b\u044c\u0437\u044f \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c <code>timestamps: false<\/code>. \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044f <code>deletedAt<\/code> \u043c\u043e\u0436\u043d\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Post = sequelize.define(   'post',   {     \/\/ \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b   },   {     paranoid: true,     deletedAt: 'destroyTime'   } )<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <code>destroy()<\/code> \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043c\u044f\u0433\u043a\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">await Post.destroy({   where: {     id: 1   } }) \/\/ UPDATE &quot;posts&quot; SET &quot;deletedAt&quot;=[timestamp] WHERE &quot;deletedAt&quot; IS NULL AND &quot;id&quot; = 1;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043d\u043e\u0438\u043a\u0430 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 <code>force: true<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">await Post.destroy({   where: {     id: 1   },   force: true })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f &quot;\u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u0433\u043e&quot; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>restore()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const post = await Post.create({ title: 'test' }) await post.destroy() console.log('\u041f\u043e\u0441\u0442 \u0443\u0434\u0430\u043b\u0435\u043d \u043c\u044f\u0433\u043a\u043e!') await post.restore() console.log('\u041f\u043e\u0441\u0442 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d!')  \/\/ \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c &quot;\u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0435&quot; \u043f\u043e\u0441\u0442\u044b, \u043d\u0430\u0431\u0440\u0430\u0432\u0448\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 100 \u043b\u0430\u0439\u043a\u043e\u0432, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 `restore()` await Post.restore({   where: {     likes: {       [Op.gt]: 100     }   } })<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0435 <code>Sequelize<\/code>, \u0431\u0443\u0434\u0443\u0442 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c &quot;\u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0435&quot; \u0437\u0430\u043f\u0438\u0441\u0438. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 <code>findAll()<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0435\u0440\u043d\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e &quot;\u043d\u0435\u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0435&quot; \u0437\u0430\u043f\u0438\u0441\u0438, \u0430 \u043c\u0435\u0442\u043e\u0434 <code>findByPk()<\/code> \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u0435\u043c\u0443 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 &quot;\u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u0439&quot; \u0437\u0430\u043f\u0438\u0441\u0438, \u0432\u0435\u0440\u043d\u0435\u0442 <code>null<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0443\u0447\u0435\u0442\u0430 &quot;\u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0445&quot; \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 <code>paranoid: false<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">await Post.findByPk(123) \/\/ null await Post.findByPk(123, { paranoid: false }) \/\/ post  await Post.findAll({   where: { foo: 'bar' } }) \/\/ [] await Post.findAll(   {     where: { foo: 'bar' }   },   { paranoid: false } ) \/\/ [post]<\/code><\/pre>\n<p>   <b><a href=\"#\">\u21a5 \u041d\u0430\u0432\u0435\u0440\u0445<\/a><\/b><\/p>\n<h2 id=\"neterpelivaya-zagruzka\">\u041d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430<\/h2>\n<p>  <\/p>\n<p>\u041d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u2014 \u044d\u0442\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u043d\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u041d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 <code>SQL<\/code> \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043e\u0434\u043d\u043e \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 (join).<\/p>\n<p>  <\/p>\n<p>\u0412 <code>Sequelize<\/code> \u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430, \u043e\u0431\u044b\u0447\u043d\u043e, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 <code>include<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const User = sequelize.define('User', { name: DataTypes.STRING }) const Task = sequelize.define('Task', { name: DataTypes.STRING }) const Tool = sequelize.define(   'Tool',   {     name: DataTypes.STRING,     size: DataTypes.STRING   },   { timestamps: false } ) User.hasMany(Task) Task.belongsTo(User) User.hasMany(Tool, { as: 'Instruments' })<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const tasks = await Task.findAll({ include: User }) console.log(JSON.stringify(tasks, null, 2)) \/* [{   &quot;name&quot;: &quot;A Task&quot;,   &quot;id&quot;: 1,   &quot;userId&quot;: 1,   &quot;user&quot;: {     &quot;name&quot;: &quot;John Smith&quot;,     &quot;id&quot;: 1   } }] *\/<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const users = await User.findAll({ include: Task }) console.log(JSON.stringify(users, null, 2)) \/* [{   &quot;name&quot;: &quot;John Smith&quot;,   &quot;id&quot;: 1,   &quot;tasks&quot;: [{     &quot;name&quot;: &quot;A Task&quot;,     &quot;id&quot;: 1,     &quot;userId&quot;: 1   }] }] *\/<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 \u0441\u0438\u043d\u043e\u043d\u0438\u043c<\/strong><\/p>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0441\u0438\u043d\u043e\u043d\u0438\u043c\u0430\u043c\u0438, \u0432\u043c\u0435\u0441\u0442\u043e <code>include<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 <code>model<\/code> \u0438 <code>as<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const users = await User.findAll({   include: { model: Tool, as: 'Instruments' } }) console.log(JSON.stringify(users, null, 2)) \/* [{   &quot;name&quot;: &quot;John Doe&quot;,   &quot;id&quot;: 1,   &quot;Instruments&quot;: [{     &quot;name&quot;: &quot;Scissor&quot;,     &quot;id&quot;: 1,     &quot;userId&quot;: 1   }] }] *\/<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u0447\u0435\u0440\u0435\u0437 \u0441\u0438\u043d\u043e\u043d\u0438\u043c\u044b:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">User.findAll({ include: 'Instruments' }) User.findAll({ include: { assosiation: 'Instruments' } })<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438<\/strong><\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 <code>required<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u2014 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>OUTER JOIN<\/code> \u0432 <code>INNER JOIN<\/code>. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">User.findAll({   include: {     model: Task,     required: true   } })<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438<\/strong><\/p>\n<p>  <\/p>\n<p>\u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 <code>where<\/code>. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u041d\u0415 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">User.findAll({   include: {     model: Tool,     as: 'Instruments',     where: {       size: {         [Op.ne]: 'small'       }     }   } })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 <code>SQL-\u0437\u0430\u043f\u0440\u043e\u0441<\/code> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">SELECT   `user`.`id`,   `user`.`name`,   `Instruments`.`id` AS `Instruments.id`,   `Instruments`.`name` AS `Instruments.name`,   `Instruments`.`size` AS `Instruments.size`,   `Instruments`.`userId` AS `Instruments.userId` FROM `users` AS `user` INNER JOIN `tools` AS `Instruments` ON   `user`.`id` = `Instruments`.`userId` AND   `Instruments`.`size` != 'small';<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 <code>where<\/code> \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>Sequelize.col()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Project.findAll({   include: {     model: Task,     where: {       state: Sequelize.col('project.state')     }   } })<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0421\u043b\u043e\u0436\u043d\u0430\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>where<\/code> \u043d\u0430 \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435<\/strong><\/p>\n<p>  <\/p>\n<p><code>Sequelize<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 <code>$nested.column$<\/code> \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>where<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">User.findAll({   where: {     '$Instruments.size$': { [Op.ne]: 'small' }   },   include: [     {       model: Tool,       as: 'Instruments'     }   ] })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 <code>SQL-\u0437\u0430\u043f\u0440\u043e\u0441<\/code> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">SELECT   `user`.`id`,   `user`.`name`,   `Instruments`.`id` AS `Instruments.id`,   `Instruments`.`name` AS `Instruments.name`,   `Instruments`.`size` AS `Instruments.size`,   `Instruments`.`userId` AS `Instruments.userId` FROM `users` AS `user` LEFT OUTER JOIN `tools` AS `Instruments` ON   `user`.`id` = `Instruments`.`userId` WHERE `Instruments`.`size` != 'small';<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c\u044b\u0445 \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435 \u0438\u043c\u0435\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043c\u0435\u0436\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e <code>where<\/code> (\u0432 <code>include<\/code>) \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u043e\u0439 <code>required<\/code> \u0438 \u0431\u0435\u0437 \u043d\u0435\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>where<\/code> \u043d\u0430 \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 <code>$nested.column$<\/code>, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c 4 \u043f\u0440\u0438\u043c\u0435\u0440\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">\/\/ \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 `where` \u0441 `required: true` \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e await User.findAll({   include: {     model: Tool,     as: 'Instruments',     where: {       size: {         [Op.ne]: 'small'       }     }   } })  \/\/ \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 `where` \u0441 `required: false` await User.findAll({   include: {     model: Tool,     as: 'Instruments',     where: {       size: {         [Op.ne]: 'small'       },       required: false     }   } })  \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 `where` \u043d\u0430 \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0441 `required: false` await User.findAll({   where: {     '$Instruments.size$': {       [Op.ne]: 'small'     }   },   include: {     model: Tool,     as: 'Instruments'   } })  \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 `where` \u043d\u0430 \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0441 `required: true` await User.findAll({   where: {     '$Instruments.size$': {       [Op.ne]: 'small'     }   },   include: {     model: Tool,     as: 'Instruments',     required: true   } })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0435 <code>SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">-- SELECT [...] FROM `users` AS `user` INNER JOIN `tools` AS `Instruments` ON   `user`.`id` = `Instruments`.`userId`   AND `Instruments`.`size` != 'small';  -- SELECT [...] FROM `users` AS `user` LEFT OUTER JOIN `tools` AS `Instruments` ON   `user`.`id` = `Instruments`.`userId`   AND `Instruments`.`size` != 'small';  -- SELECT [...] FROM `users` AS `user` LEFT OUTER JOIN `tools` AS `Instruments` ON   `user`.`id` = `Instruments`.`userId` WHERE `Instruments`.`size` != 'small';  -- SELECT [...] FROM `users` AS `user` INNER JOIN `tools` AS `Instruments` ON   `user`.`id` = `Instruments`.`userId` WHERE `Instruments`.`size` != 'small';<\/code><\/pre>\n<p>  <\/p>\n<p><code>include<\/code> \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Foo.findAll({   include: [     {       model: Bar,       required: true     },     {       model: Baz,       where: {         \/* ... *\/       }     },     Qux \/\/ \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0434\u043b\u044f `{ model: Qux }`   ] })<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u041d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c<\/strong><\/p>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 <code>Sequelize<\/code> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Foo = sequelize.define('Foo', { name: DataTypes.STRING }) const Bar = sequelize.define('Bar', { name: DataTypes.STRING }) Foo.belongsToMany(Bar, { through: 'Foo_Bar' }) Bar.belongsToMany(Foo, { through: 'Foo_Bar' })  await sequelize.sync() const foo = await Foo.create({ name: 'foo' }) const bar = await Bar.create({ name: 'bar' }) await foo.addBar(bar) const fetchedFoo = Foo.findOne({ include: Bar }) copnsole.log(JSON.stringify(fetchedFoo, null, 2)) \/* {   &quot;id&quot;: 1,   &quot;name&quot;: &quot;foo&quot;,   &quot;Bars&quot;: [     {       &quot;id&quot;: 1,       &quot;name&quot;: &quot;bar&quot;,       &quot;Foo_Bar&quot;: {         &quot;FooId&quot;: 1,         &quot;BarId&quot;: 1       }     }   ] } *\/<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 <code>attributes<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u044b\u0435 \u0432 \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Foo.findAll({   include: [     {       model: Bar,       through: {         attributes: [           \/* \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b *\/         ]       }     }   ] })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u044b \u0442\u0430\u043a\u0438\u0435 \u043f\u043e\u043b\u044f, \u0432 <code>attributes<\/code> \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0443\u0441\u0442\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Foo.findOne({   include: {     model: Bar,     attributes: []   } }) \/* {   &quot;id&quot;: 1,   &quot;name&quot;: &quot;foo&quot;,   &quot;Bars&quot;: [     {       &quot;id&quot;: 1,       &quot;name&quot;: &quot;bar&quot;     }   ] } *\/<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u044b\u0435 \u043f\u043e\u043b\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043c\u043e\u0436\u043d\u043e \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 <code>where<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">User.findAll({   include: [     {       model: Project,       through: {         where: {           completed: true         }       }     }   ] })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 <code>SQL-\u0437\u0430\u043f\u0440\u043e\u0441<\/code> (<code>sqlite<\/code>):<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">SELECT   `User`.`id`,   `User`.`name`,   `Projects`.`id` AS `Projects.id`,   `Projects`.`name` AS `Projects.name`,   `Projects-&gt;User_Project`.`completed` AS `Projects.User_Project.completed`,   `Projects-&gt;User_Project`.`UserId` AS `Projects.User_Project.UserId`,   `Projects-&gt;User_Project`.`ProjectId` AS `Projects.User_Project.ProjectId` FROM `Users` AS `User` LEFT OUTER JOIN `User_Projects` AS `Projects-&gt;User_Project` ON   `User`.`id` = `Projects-&gt;User_Project`.`UserId` LEFT OUTER JOIN `Projects` AS `Projects` ON   `Projects`.`id` = `Projects-&gt;User_Project`.`ProjectId` AND   `Projects-&gt;User_Project`.`completed` = 1;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 <code>all<\/code> \u0438 <code>nested<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">\/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 `User` User.findAll({ include: { all: true } })  \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 `User`, \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u0441 \u043d\u0438\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 User.findAll({ include: { all: true, nested: true } })<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u043f\u0440\u0438 \u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435<\/strong><\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 <code>order<\/code> (\u043d\u0430 \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435):<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Company.findAll({   include: Division,   order: [     \/\/ \u043c\u0430\u0441\u0441\u0438\u0432 \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u043c\u043e\u0434\u0435\u043b\u0438     \/\/ \u0437\u0430\u0442\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u0438 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438     [Division, 'name', 'ASC']   ] })  Company.findAll({   include: Division,   order: [[Division, 'name', 'DESC']] })  Company.findAll({   \/\/ \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0438\u043d\u043e\u043d\u0438\u043c\u0430   include: { model: Division, as: 'Div' },   order: [[{ model: Division, as: 'Div' }, 'name', 'DESC']] })  Company.findAll({   \/\/ \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438   include: {     model: Division,     include: Department   },   order: [[Division, Department, 'name', 'DESC']] })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u043f\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 <code>Division<\/code> \u0438 <code>Department<\/code> \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0442\u0430\u043a\u0438\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f, \u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>DepartmentDivision<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Company.findAll({   include: {     model: Division,     include: Department   },   order: [[Division, DepartmentDivision, 'name', 'ASC']] })<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0412\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430<\/strong><\/p>\n<p>  <\/p>\n<p>\u0412\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0432\u0441\u0435\u0445 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const users = await User.findAll({   include: {     model: Tool,     as: 'Instruments',     include: {       model: Teacher,       include: [         \/* \u0438 \u0442.\u0434. *\/       ]     }   } }) console.log(JSON.stringify(users, null, 2)) \/* [{   &quot;name&quot;: &quot;John Smith&quot;,   &quot;id&quot;: 1,   &quot;Instruments&quot;: [{ \/\/ \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f 1:M \u0438 N:M     &quot;name&quot;: &quot;Scissor&quot;,     &quot;id&quot;: 1,     &quot;userId&quot;: 1,     &quot;Teacher&quot;: { \/\/ \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f 1:1       &quot;name&quot;: &quot;Jimi Hendrix&quot;     }   }] }] *\/<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0432\u043d\u0435\u0448\u043d\u0435\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 (<code>OUTER JOIN<\/code>). \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 <code>where<\/code> \u043a \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 (<code>INNER JOIN<\/code>) \u2014 \u0431\u0443\u0434\u0443\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0435 \u043f\u043e\u0434\u043c\u043e\u0434\u0435\u043b\u0438. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 <code>required: false<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">User.findAll({   include: [     {       model: Tool,       as: 'Instruments',       include: [         {           model: Teacher,           where: {             school: 'Woodstock Music School'           },           required: false         }       ]     }   ] })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0435\u0440\u043d\u0435\u0442 \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0445 \u0443\u0447\u0438\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0441 <code>Woodstock Music School<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 <code>findAndCountAll()<\/code> \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 <code>include<\/code>. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u0438, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u043a\u0430\u043a <code>required<\/code>, \u0431\u0443\u0434\u0443\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f <code>count<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">User.findAndCountAll({   include: [{ model: Profile, required: true }],   limit: 3 })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c 3 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0444\u0438\u043b\u0438. \u0415\u0441\u043b\u0438 \u043c\u044b \u043e\u043f\u0443\u0441\u0442\u0438\u043c <code>required<\/code>, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c 3 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0442\u043e\u0433\u043e, \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0443 \u043d\u0438\u0445 \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u0438\u043b\u0438 \u043d\u0435\u0442. \u0412\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <code>where<\/code> \u0432 <code>include<\/code> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">User.findAndCountAll({   include: [{ model: Profile, where: { active: true } }],   limit: 3 })<\/code><\/pre>\n<p>   <b><a href=\"#\">\u21a5 \u041d\u0430\u0432\u0435\u0440\u0445<\/a><\/b><\/p>\n<h2 id=\"sozdanie-ekzemplyarov-s-associaciyami\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u0441 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f\u043c\u0438<\/h2>\n<p>  <\/p>\n<p>\u042d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d \u0441\u0440\u0430\u0437\u0443 \u0441 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0435\u0439. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<p><strong><code>belongsTo()<\/code>, <code>hasMany()<\/code>, <code>hasOne()<\/code><\/strong><\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Product = sequelize.define('product', {   title: DataTypes.STRING }) const User = sequelize.define('user', {   firstName: DataTypes.STRING,   lastName: DataTypes.STRING }) const Address = sequelize.define('address', {   type: DataTypes.STRING,   line1: DataTypes.STRING,   line2: DataTypes.STRING,   city: DataTypes.STRING,   state: DataTypes.STRING,   zip: DataTypes.STRING }) \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Product.User = Product.belongsTo(User) User.Address = User.hasMany(Address)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e\u0432\u044b\u0439 <code>Product<\/code>, <code>User<\/code> \u0438 \u043e\u0434\u0438\u043d \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 <code>Address<\/code> \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const product = await Product.create(   {     title: 'Product',     user: {       firstName: 'John',       lastName: 'Smith',       addresses: [         {           type: 'home',           line1: 'street',           city: 'city',           state: 'state',           zip: '12345'         }       ]     }   },   {     include: [       {         assosiation: Product.User,         include: [User.Addresses]       }     ]   } )<\/code><\/pre>\n<p>  <\/p>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/em>: \u043d\u0430\u0448\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>user<\/code> \u0441 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0439 \u0431\u0443\u043a\u0432\u044b <code>u<\/code>. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f <code>user<\/code>. \u0415\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u043a\u0430\u043a <code>User<\/code>, \u0442\u043e \u0434\u043b\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>User<\/code>. \u0422\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f <code>addresses<\/code>, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u043f\u043b\u044e\u0440\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e (\u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0432\u043e \u043c\u043d\u043e\u0436\u0435\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e).<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Creator = Product.belongsTo(User, { as: 'creator' })  const product = await Product.create(   {     title: 'Chair',     creator: {       firstName: 'John',       lastName: 'Smith'     }   },   {     include: [Creator]   } )<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043c\u0435\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u043f\u0440\u043e\u0434\u0443\u043a\u0442 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0442\u0435\u0433\u0430\u043c\u0438. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Tag = sequelize.define('tag', {   name: DataTypes.STRING }) Product.hasMany(Tag) \/\/ \u0438\u043b\u0438 `belongsToMany()`<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0434\u0443\u043a\u0442 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0442\u0435\u0433\u0430\u043c\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const product = await Product.create(   {     id: 1,     title: 'Chair',     tags: [{ name: 'Alpha' }, { name: 'Beta' }]   },   {     include: [Tag]   } )<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418 \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u0441\u0438\u043d\u043e\u043d\u0438\u043c\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Categories = Product.hasMany(Tag, { as: 'categories' })  const product = awaity Product.create({   id: 1,   title: 'Chair',   categories: [     { id: 1, name: 'Alpha' },     { id: 2, name: 'Beta' }   ] }, {   include: [{     association: Categories,     as: 'categories'   }] })<\/code><\/pre>\n<p>   <b><a href=\"#\">\u21a5 \u041d\u0430\u0432\u0435\u0440\u0445<\/a><\/b><\/p>\n<h2 id=\"prodvinutye-associacii-mn\">\u041f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0435 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 M:N<\/h2>\n<p>  <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 <code>User<\/code> \u0438 <code>Profile<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const User = sequelize.define(   'user',   {     username: DataTypes.STRING,     points: DataTypes.INTEGER   },   { timestamps: false } ) const Profile = sequelize.define(   'profile',   {     name: DataTypes.STRING   },   { timastamps: false } )  User.belongsToMany(Profile, { through: 'User_Profiles' }) Profile.belongsToMany(User, { through: 'User_Profiles' })<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 <code>through<\/code>, \u043c\u044b \u043f\u0440\u043e\u0441\u0438\u043c <code>Sequelize<\/code> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u2014 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>User_Profiles<\/code>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e 2 \u043a\u043e\u043b\u043e\u043d\u043a\u0438: <code>userId<\/code> \u0438 <code>profileId<\/code>. \u0412 \u044d\u0442\u0438 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0435 (unique composite) \u043a\u043b\u044e\u0447\u0438.<\/p>\n<p>  <\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0435\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0435\u0439. \u041c\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432 \u0442\u0430\u043a\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const User_Profile = sequelize.define(   'User_Profile',   {     selfGranted: DataTypes.BOOLEAN   },   { timestamps: false } )<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u043e\u043e\u043f\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438\u0437 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <code>user.addProfile()<\/code> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 <code>through<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const amidala = await User.create({ username: 'p4dm3', points: 1000 }) const queen = await Profile.create({ name: 'Queen' }) await amidala.addProfile(queen, { through: { selfGranted: false } })<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043e\u0442\u043c\u0435\u0447\u0430\u043b\u043e\u0441\u044c, \u0432\u0441\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0432 \u043e\u0434\u043d\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 <code>create()<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const amidala = await User.create(   {     username: 'p4dm3',     points: 1000,     profiles: [       {         name: 'Queen',         User_Profile: {           selfGranted: true         }       }     ]   },   {     include: Profile   } )<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0432\u044b \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u0447\u0442\u043e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>User_Profiles<\/code> \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e\u043b\u0435 <code>id<\/code>. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u044e\u0447, \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 <code>uniqueKey<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">User.belongsToMany(Profile, {   through: User_Profile,   uniqueKey: 'customUnique' })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u043c\u0435\u0441\u0442\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e, \u0432 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const User_Profile = sequelize.define(   'User_Profile',   {     id: {       type: DataTypes.INTEGER,       primaryKey: true,       autoIncrement: true,       allowNull: false     },     selfGranted: DataTypes.BOOLEAN   },   { timestamps: false } )<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0410\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f &quot;\u0441\u0443\u043f\u0435\u0440 \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c&quot;<\/strong><\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0448\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const User = sequelize.define(   'user',   {     username: DataTypes.STRING,     points: DataTypes.INTEGER   },   { timestamps: false } )  const Profile = sequelize.define(   'profile',   {     name: DataTypes.STRING   },   { timestamps: false } )  \/\/ \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 const Grant = sequelize.define(   'grant',   {     id: {       type: DataTypes.INTEGER,       primaryKey: true,       autoIncrement: true,       allowNull: false     },     selfGranted: DataTypes.BOOLEAN   },   { timestamps: false } )<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 <code>User<\/code> \u0438 <code>Profile<\/code> \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u044c <code>Grant<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">User.belongsToMany(Profile, { through: Grant }) Profile.belongsToMany(User, { through: Grant })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a?<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">\/\/ \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043e\u0434\u0438\u043d-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u043c\u0435\u0436\u0434\u0443 `User` \u0438 `Grant` User.hasMany(Grant) Grant.belongsTo(User)  \/\/ \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043e\u0434\u0438\u043d-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u043c\u0435\u0436\u0434\u0443 `Profile` \u0438 `Grant` Profile.hasMany(Grant) Grant.belongsTo(Profile)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u0438\u043c \u0436\u0435! \u042d\u0442\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e <code>User.hasMany(Grant)<\/code> \u0438 <code>Profile.hasMany(Grant)<\/code> \u0437\u0430\u043f\u0438\u0448\u0443\u0442 <code>userId<\/code> \u0438 <code>profileId<\/code> \u0432 <code>Grant<\/code>.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043e\u0442 \u0434\u0432\u0443\u0445 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u043e\u0434\u0438\u043d-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043e\u0442\u043b\u0438\u0447\u0438\u0435\u043c \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">\/\/ \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a User.findAll({ include: Profile }) Profile.findAll({ include: User }) \/\/ \u043d\u043e \u043d\u0435 \u0442\u0430\u043a User.findAll({ include: Grant }) Profile.findAll({ include: Grant }) Grant.findAll({ include: User }) Grant.findAll({ include: Profile })  \/\/ \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043f\u0430\u0440\u0430 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u043e\u0434\u0438\u043d-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 User.findAll({ include: Grant }) Profile.findAll({ include: Grant }) Grant.findAll({ include: User }) Grant.findAll({ include: Profile }) \/\/ \u043d\u043e \u043d\u0435 \u0442\u0430\u043a User.findAll({ include: Profile }) Profile.findAll({ include: User })  \/\/ \u0445\u043e\u0442\u044f \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u043c\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0447\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0435 User.findAll({   include: {     model: Grant,     include: Profile   } }) \/*   \u042d\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 `User.findAll({ include: Profile })`, \u043d\u043e   \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u0439.   \u0412\u043c\u0435\u0441\u0442\u043e `user.profiles[].grant` \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c `user.grants[].profiles[]` *\/<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0434\u043b\u044f \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">User.belongsToMany(Profile, { through: Grant }) Profile.belongsToMany(User, { through: Grant }) User.hasMany(Grant) Grant.belongsTo(User) Profile.hasMany(Grant) Grant.belongsTo(Profile)  \/\/ \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 User.findAll({ include: Profile }) Profile.findAll({ include: User }) User.findAll({ include: Grant }) Profile.findAll({ include: Grant }) Grant.findAll({ include: User }) Grant.findAll({ include: Profile })<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0432\u0441\u0435 \u0432\u0438\u0434\u044b \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">User.findAll({   include: [     {       model: Grant,       include: [User, Profile]     },     {       model: Profile,       include: {         model: User,         include: {           model: Grant,           include: [User, Profile]         }       }     }   ] })<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0421\u0438\u043d\u043e\u043d\u0438\u043c\u044b \u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0435\u0439<\/strong><\/p>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0435\u0439 \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u0441\u0438\u043d\u043e\u043d\u0438\u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Product.belongsToMany(Category, { as: 'groups', through: 'product_categories' }) Category.belongsToMany(Product, { as: 'items', through: 'product_categories' })  \/\/ \u041d\u0415 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 await Product.findAll({ include: Category })  \/\/ \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 await Product.findAll({   include: {     model: Category,     as: 'groups'   } })  \/\/ \u044d\u0442\u043e \u0442\u043e\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 await Product.findAll({ include: 'groups' })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 <code>SQL-\u0437\u0430\u043f\u0440\u043e\u0441<\/code> \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>product_categories<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">CREATE TABLE IF NOT EXISTS `product_categories` (   `createdAt` DATETIME NOT NULL,   `updatedAt` DATETIME NOT NULL,   `productId` INTEGER NOT NULL REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,   `categoryId` INTEGER NOT NULL REFERENCES `categories` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,   PRIMARY KEY (`productId`, `categoryId`) );<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f <code>productId<\/code> \u0438 <code>categoryId<\/code>. \u0414\u043b\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 <code>foreignKey<\/code> \u0438 <code>otherKey<\/code>, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e (<code>foreignKey<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043a\u043b\u044e\u0447 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430, \u0430 <code>otherKey<\/code> \u2014 \u0434\u043b\u044f \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438).<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Product.belongsToMany(Category, {   through: 'product_categories',   foreignKey: 'objectId', \/\/ \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 `productId`   otherKey: 'typeIf' \/\/ \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 `categoryId` }) Category.belongsToMany(Product, {   through: 'product_categories',   foreignKey: 'typeId', \/\/  \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 `categoryId`   otherKey: 'objectId' \/\/  \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 `productId` })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 <code>SQL-\u0437\u0430\u043f\u0440\u043e\u0441<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">CREATE TABLE IF NOT EXISTS `product_categories` (   `createdAt` DATETIME NOT NULL,   `updatedAt` DATETIME NOT NULL,   `objectId` INTEGER NOT NULL REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,   `typeId` INTEGER NOT NULL REFERENCES `categories` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,   PRIMARY KEY (`objectId`, `typeId`) );<\/code><\/pre>\n<p>  <\/p>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/em>: \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 <code>foreignKey<\/code> \u0438 <code>otherKey<\/code> \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u043e\u0431\u043e\u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u0430\u0445. \u0415\u0441\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0438\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0434\u043d\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435, \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 <code>Sequelize<\/code> \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u043c.<\/p>\n<p>  <\/p>\n<p><code>Sequelize<\/code> \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">Person.belongsToMany(Person, { as: 'Children', through: 'PersonChildren' }) \/\/ \u044d\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 `PersonChildren` \u0441 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/strong><\/p>\n<p>  <\/p>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u0440\u0438 \u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0435\u0439 \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 (<code>User.findOne({ include: Profile })<\/code>):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">{   &quot;id&quot;: 4,   &quot;username&quot;: &quot;p4dm3&quot;,   &quot;points&quot;: 1000,   &quot;profiles&quot;: [     {       &quot;id&quot;: 6,       &quot;name&quot;: &quot;queen&quot;,       &quot;grant&quot;: {         &quot;userId&quot;: 4,         &quot;profileId&quot;: 6,         &quot;selfGranted&quot;: false       }     }   ] }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043d\u0435\u0448\u043d\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u2014 \u044d\u0442\u043e <code>User<\/code>, \u0443 \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u0435 <code>profiles<\/code> \u2014 \u043c\u0430\u0441\u0441\u0438\u0432 <code>Profile<\/code>, \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e <code>Profile<\/code> \u0435\u0441\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 <code>grant<\/code> \u2014 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>Grant<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u044f \u0438\u0437 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 <code>attributes<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">User.findOne({   include: {     model: Profile,     through: {       attributes: ['selfGranted']     }   } }) \/* {   &quot;id&quot;: 4,   &quot;username&quot;: &quot;p4dm3&quot;,   &quot;points&quot;: 1000,   &quot;profiles&quot;: [     {       &quot;id&quot;: 6,       &quot;name&quot;: &quot;queen&quot;,       &quot;grant&quot;: {         &quot;selfGranted&quot;: false       }     }   ] } *\/<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f <code>grant<\/code> \u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c <code>attributes: []<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043c\u0438\u043a\u0441\u0438\u043d\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>user.getProfiles()<\/code>), \u0432\u043c\u0435\u0441\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>User.findAll()<\/code>), \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u0435\u0439 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 <code>joinTableAttributes<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">user.getProfiles({ joinTableAttributes: ['selfGranted'] }) \/* [   {     &quot;id&quot;: 6,     &quot;name&quot;: &quot;queen&quot;,     &quot;grant&quot;: {       &quot;selfGranted&quot;: false     }   } ] *\/<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0410\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u0438 \u0442.\u0434.<\/strong><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u043c \u0438\u0433\u0440\u0443. \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0438\u0433\u0440\u043e\u043a\u0438 \u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b. \u041a\u043e\u043c\u0430\u043d\u0434\u044b \u0438\u0433\u0440\u0430\u044e\u0442 \u0432 \u0438\u0433\u0440\u044b. \u0418\u0433\u0440\u043e\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u043c\u0435\u043d\u044f\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0432 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u0447\u0435\u043c\u043f\u0438\u043e\u043d\u0430\u0442\u0430 (\u043d\u043e \u043d\u0435 \u0432 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u0438\u0433\u0440\u044b). \u0412 \u043e\u0434\u043d\u043e\u0439 \u0438\u0433\u0440\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0432\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0441\u0432\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0438\u0433\u0440\u043e\u043a\u043e\u0432 (\u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0438\u0433\u0440\u044b).<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Player = sequelize.define('Player', { username: DataTypes.STRING }) const Team = sequelize.define('Team', { name: DataTypes.STRING }) const Game = sequelize.define('Game', { name: DataTypes.INTEGER })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u043f\u0440\u043e\u0441: \u043a\u0430\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044e \u043c\u0435\u0436\u0434\u0443 \u044d\u0442\u0438\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438?<\/p>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043e\u0434\u043d\u0430 \u0438\u0433\u0440\u0430 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u043d\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434 (\u0442\u0435\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0433\u0440\u0430\u044e\u0442 \u0432 \u044d\u0442\u043e\u0439 \u0438\u0433\u0440\u0435)<\/li>\n<li>\u043e\u0434\u043d\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0443\u0447\u0430\u0441\u0442\u0438\u0435 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0438\u0433\u0440\u0430\u0445<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 <code>Game<\/code> \u0438 <code>Team<\/code> \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c. \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441\u0443\u043f\u0435\u0440-\u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u043d\u043e\u0439 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 (\u043a\u0430\u043a \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435):<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const GameTeam = sequelize.define('GameTeam', {   id: {     type: DataTypes.INTEGER,     primaryKey: true,     autoIncrement: true,     allowNull: false   } }) Team.belongsToMany(Game, { through: GameTeam }) Game.belongsToMany(Team, { through: GameTeam }) GameTeam.belongsTo(Game) GameTeam.belongsTo(Team) Game.hasMany(GameTeam) Team.hasMany(GameTeam)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421 \u0438\u0433\u0440\u043e\u043a\u0430\u043c\u0438 \u0432\u0441\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435. \u041d\u0430\u0431\u043e\u0440 \u0438\u0433\u0440\u043e\u043a\u043e\u0432, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0432 \u043a\u0430\u043a\u043e\u0439 \u0438\u0433\u0440\u0435 \u0434\u0430\u043d\u043d\u0430\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u0435\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u0430 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u043c\u0435\u0436\u0434\u0443 <code>Player<\/code> \u0438 <code>Team<\/code>. \u041d\u0430\u043c \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u0430 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u043c\u0435\u0436\u0434\u0443 <code>Player<\/code> \u0438 <code>Game<\/code>. \u0412\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 <code>Player<\/code> \u043a \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u043d\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f \u043c\u0435\u0436\u0434\u0443 <code>Player<\/code> \u0438 \u0447\u0435\u043c-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 &quot;\u043f\u0430\u0440\u043d\u043e\u0433\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430-\u0438\u0433\u0440\u0430&quot;, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0430\u0440\u0430 (\u043a\u043e\u043c\u0430\u043d\u0434\u0430 + \u0438\u0433\u0440\u0430) \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u0431\u043e\u0440 \u0438\u0433\u0440\u043e\u043a\u043e\u0432. \u0412\u043d\u0435\u0437\u0430\u043f\u043d\u043e, \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0438\u0441\u043a\u0430\u043b\u0438, \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 <code>GameTeam<\/code>! \u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f, \u0447\u0442\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0430\u044f \u043f\u0430\u0440\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430-\u0438\u0433\u0440\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0433\u0440\u043e\u043a\u043e\u0432 \u0438 \u043e\u0434\u0438\u043d \u0438\u0433\u0440\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0430\u0440\u0430\u0445, \u043d\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u043c\u0435\u0436\u0434\u0443 <code>Player<\/code> \u0438 <code>GameTeam<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 \u0441\u043d\u043e\u0432\u0430 \u043f\u0440\u0438\u0431\u0435\u0433\u043d\u0435\u043c \u043a \u0441\u0443\u043f\u0435\u0440-\u0432\u0435\u0440\u0441\u0438\u0438 M:N:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const PlayerGameTeam = sequelize.define('PlayerGameTeam', {   id: {     type: DataTypes.INTEGER,     primaryKey: true,     autoIncrement: true,     allowNull: false   } }) Player.belongsToMany(GameTeam, { through: PlayerGameTeam }) GameTeam.belongsToMany(Player, { through: PlayerGameTeam }) PlayerGameTeam.belongsTo(Player) PlayerGameTeam.belongsTo(GameTeam) Player.hasMany(PlayerGameTeam) GameTeam.hasMany(PlayerGameTeam)<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u0430 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f \u0434\u0435\u043b\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const { Sequelize, Op, Model, DataTypes } = require('sequelize')  const sequelize = new Sequelize('sqlite::memory:', {   define: { timestamps: false } \/\/ \u041f\u0440\u043e\u0441\u0442\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c\u0441\u044f })  const Player = sequelize.define('Player', { username: DataTypes.STRING }) const Team = sequelize.define('Team', { name: DataTypes.STRING }) const Game = sequelize.define('Game', { name: DataTypes.INTEGER })  \/\/ \u0410\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f \u0441\u0443\u043f\u0435\u0440-\u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u043c\u0435\u0436\u0434\u0443 `Game` \u0438 `Team` const GameTeam = sequelize.define('GameTeam', {   id: {     type: DataTypes.INTEGER,     primaryKey: true,     autoIncrement: true,     allowNull: false   } }) Team.belongsToMany(Game, { through: GameTeam }) Game.belongsToMany(Team, { through: GameTeam }) GameTeam.belongsTo(Game) GameTeam.belongsTo(Team) Game.hasMany(GameTeam) Team.hasMany(GameTeam)  \/\/ \u0410\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f \u0441\u0443\u043f\u0435\u0440-\u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c \u043c\u0435\u0436\u0434\u0443 `Player` \u0438 `GameTeam` const PlayerGameTeam = sequelize.define('PlayerGameTeam', {   id: {     type: DataTypes.INTEGER,     primaryKey: true,     autoIncrement: true,     allowNull: false   } }) Player.belongsToMany(GameTeam, { through: PlayerGameTeam }) GameTeam.belongsToMany(Player, { through: PlayerGameTeam }) PlayerGameTeam.belongsTo(Player) PlayerGameTeam.belongsTo(GameTeam) Player.hasMany(PlayerGameTeam) GameTeam.hasMany(PlayerGameTeam) ;(async () =&gt; {   await sequelize.sync()   \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u0433\u0440\u043e\u043a\u043e\u0432   await Player.bulkCreate([     { username: 's0me0ne' },     { username: 'empty' },     { username: 'greenhead' },     { username: 'not_spock' },     { username: 'bowl_of_petunias' }   ])   \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u0433\u0440\u044b   await Game.bulkCreate([     { name: 'The Big Clash' },     { name: 'Winter Showdown' },     { name: 'Summer Beatdown' }   ])   \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b   await Team.bulkCreate([     { name: 'The Martians' },     { name: 'The Earthlings' },     { name: 'The Plutonians' }   ])    \/\/ \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u043a\u0430\u043a\u0430\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0432 \u043a\u0430\u043a\u043e\u0439 \u0438\u0433\u0440\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u0435\u0442. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c   \/\/ \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0430 `setTeams()` \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0433\u0440\u044b.   \/\/ \u041e\u0434\u043d\u0430\u043a\u043e, \u0434\u043b\u044f \u0447\u0438\u0441\u0442\u043e\u0442\u044b \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u044f\u0432\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b `create()`   await GameTeam.bulkCreate([     { GameId: 1, TeamId: 1 }, \/\/ \u044d\u0442\u0430 `GameTeam` \u043f\u043e\u043b\u0443\u0447\u0438\u0442 `id` 1     { GameId: 1, TeamId: 2 }, \/\/ \u0438 \u0442.\u0434.     { GameId: 2, TeamId: 1 },     { GameId: 2, TeamId: 3 },     { GameId: 3, TeamId: 2 },     { GameId: 3, TeamId: 3 }   ])    \/\/ \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0438\u0433\u0440\u043e\u043a\u043e\u0432.   \/\/ \u0421\u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0432\u0442\u043e\u0440\u043e\u0439 \u0438\u0433\u0440\u044b (Winter Showdown).   await PlayerGameTeam.bulkCreate([     { PlayerId: 1, GameTeamId: 3 }, \/\/ s0me0ne \u0438\u0433\u0440\u0430\u0435\u0442 \u0437\u0430 The Martians     { PlayerId: 3, GameTeamId: 3 }, \/\/ \u0438 \u0442.\u0434.     { PlayerId: 4, GameTeamId: 4 },     { PlayerId: 5, GameTeamId: 4 }   ])    \/\/ \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b!   const game = await Game.findOne({     where: {       name: 'Winter Showdown'     },     include: {       model: GameTeam,       include: [         {           model: Player,           through: { attributes: [] } \/\/ \u0421\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043d\u0435\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b `PlayerGameTeam` \u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432         },         Team       ]     }   })    console.log(`\u041e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0430 \u0438\u0433\u0440\u0430: &quot;${game.name}&quot;`)   for (let i = 0; i &lt; game.GameTeams.length; i++) {     const team = game.GameTeams[i].Team     const players = game.GameTeams[i].Players     console.log(       `- \u041a\u043e\u043c\u0430\u043d\u0434\u0430 &quot;${team.name}&quot; \u0438\u0433\u0440\u0430\u0435\u0442 \u0432 \u0438\u0433\u0440\u0443 &quot;${game.name}&quot; \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u0438\u0433\u0440\u043e\u043a\u0430\u043c\u0438:`     )     console.log(players.map((p) =&gt; `--- ${p.username}`).join('\\n'))   } })()<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b\u0432\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">\u041e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0430 \u0438\u0433\u0440\u0430: &quot;Winter Showdown&quot; - \u041a\u043e\u043c\u0430\u043d\u0434\u0430 &quot;The Martians&quot; \u0438\u0433\u0440\u0430\u0435\u0442 \u0432 \u0438\u0433\u0440\u0443 &quot;Winter Showdown&quot; \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u0438\u0433\u0440\u043e\u043a\u0430\u043c\u0438: --- s0me0ne --- greenhead - \u041a\u043e\u043c\u0430\u043d\u0434\u0430 &quot;The Plutonians&quot; \u0438\u0433\u0440\u0430\u0435\u0442 \u0432 \u0438\u0433\u0440\u0443 &quot;Winter Showdown&quot; \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u0438\u0433\u0440\u043e\u043a\u0430\u043c\u0438: --- not_spock --- bowl_of_petunias<\/code><\/pre>\n<p>   <b><a href=\"#\">\u21a5 \u041d\u0430\u0432\u0435\u0440\u0445<\/a><\/b><\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e\u0431 \u043e\u0431\u043b\u0430\u0441\u0442\u044f\u0445 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439, \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u044b\u0445 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f\u0445, \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u0445, \u0445\u0443\u043a\u0430\u0445, \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e \u043c\u043d\u043e\u0433\u043e\u043c \u0434\u0440\u0443\u0433\u043e\u043c.<\/p>\n<p>  <\/p>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438 \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0434\u043d\u044f!<\/p>\n<p>  <\/p>\n<hr>\n<p>  <\/p>\n<p><a href=\"https:\/\/macloud.ru\/cloud-vps\">\u0410\u0440\u0435\u043d\u0434\u0430 \u043e\u0431\u043b\u0430\u0447\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/a> \u0441 \u0431\u044b\u0441\u0442\u0440\u044b\u043c\u0438 NVM\u0435-\u0434\u0438\u0441\u043a\u0430\u043c\u0438 \u0438 \u043f\u043e\u0441\u0443\u0442\u043e\u0447\u043d\u043e\u0439 \u043e\u043f\u043b\u0430\u0442\u043e\u0439 \u0443 \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0430 \u041c\u0430\u043a\u043b\u0430\u0443\u0434.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/macloud.ru\/vps-vds&amp;utm_source=habr&amp;utm_medium=original&amp;utm_campaign=igor\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/gj\/zs\/hm\/gjzshmojh-bmnbzvfsre9se1eta.png\"><\/a><\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/macloud\/blog\/566036\/\"> https:\/\/habr.com\/ru\/company\/macloud\/blog\/566036\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/gu\/0h\/ok\/gu0hokcjqofxktdkr7hkerc1zxm.jpeg\">  <\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e <code>Sequelize<\/code>.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/sequelize.org\/master\/\"><code>Sequelize<\/code><\/a> \u2014 \u044d\u0442\u043e <a href=\"https:\/\/ru.wikipedia.org\/wiki\/ORM\"><code>ORM<\/code><\/a> (Object-Relational Mapping \u2014 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435) \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A1%D0%B8%D1%81%D1%82%D0%B5%D0%BC%D0%B0_%D1%83%D0%BF%D1%80%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F_%D0%B1%D0%B0%D0%B7%D0%B0%D0%BC%D0%B8_%D0%B4%D0%B0%D0%BD%D0%BD%D1%8B%D1%85\">\u0421\u0423\u0411\u0414<\/a> (\u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f (\u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u044b\u043c\u0438) \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, Relational Database Management System, RDBMS), \u043a\u0430\u043a <code>Postgres<\/code>, <code>MySQL<\/code>, <code>MariaDB<\/code>, <code>SQLite<\/code> \u0438 <code>MSSQL<\/code>. \u042d\u0442\u043e \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f <code>ORM<\/code> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0434\u0430\u043b\u0435\u0435 \u2014 \u0411\u0414), \u043d\u043e, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043e\u0434\u043d\u0430 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0445 \u0438, \u0447\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, &quot;battle tested&quot; (\u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c).<\/p>\n<p>  <\/p>\n<p><code>ORM<\/code> \u0445\u043e\u0440\u043e\u0448\u0438 \u0442\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0411\u0414 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (<code>JavaScript<\/code>), \u0442.\u0435. \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u043e\u0432 (<code>SQL<\/code>). \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0411\u0414 \u043b\u0435\u0433\u0447\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>SQL<\/code> (\u0438\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e c \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0433\u043e). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u0434 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u0431\u0435\u0433\u043b\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043d\u0430 <code>SQL<\/code>. \u0412\u043e\u0442 <a href=\"https:\/\/habr.com\/ru\/company\/macloud\/blog\/564390\/\">\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430<\/a>.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0438\u0437 3 \u0447\u0430\u0441\u0442\u0435\u0439 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0445 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f\u0445 (\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u0445 \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438), &quot;\u043f\u0430\u0440\u0430\u043d\u043e\u0438\u043a\u0435&quot;, \u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u043e\u0439 \u0438 \u043b\u0435\u043d\u0438\u0432\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e \u043c\u043d\u043e\u0433\u043e\u043c \u0434\u0440\u0443\u0433\u043e\u043c.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 <a href=\"https:\/\/habr.com\/ru\/company\/macloud\/blog\/565062\/\">\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u0435\u0440\u0432\u0443\u044e \u0447\u0430\u0441\u0442\u044c<\/a>.<\/p>\n<p>  <\/p>\n<p>\u042f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0431\u044b\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u043c (\u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0431\u0435\u0437 \u0443\u0449\u0435\u0440\u0431\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430). \u042f \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0438\u0437\u043b\u0430\u0433\u0430\u0442\u044c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u044f\u0437\u044b\u043a\u043e\u043c. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c\u044b\u0445 \u0432 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435, \u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u044b \u0438\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-326138","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/326138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=326138"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/326138\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=326138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=326138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=326138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}