UNPKG

sequelize

Version:

Multi dialect ORM for Node.JS/io.js

1,074 lines (707 loc) 37.7 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <base data-ice="baseUrl" href="../../../"> <title data-ice="title">BelongsToMany | Sequelize | The node.js ORM for PostgreSQL, MySQL, SQLite and MSSQL API Document</title> <link type="text/css" rel="stylesheet" href="css/style.css"> <link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css"> <script src="script/prettify/prettify.js"></script> <script src="script/manual.js"></script> <link data-ice="userStyle" rel="stylesheet" href="user/css/0-style.css"> </head> <body class="layout-container" data-ice="rootContainer"> <header> <a href="./">Home</a> <a href="identifiers.html">Reference</a> <a href="source.html">Source</a> <a data-ice="repoURL" href="https://github.com/sequelize/sequelize.git" class="repo-url-github">Repository</a> <div class="search-box"> <span> <img src="./image/search.png"> <span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span> </span> <ul class="search-result"></ul> </div> </header> <nav class="navigation" data-ice="nav"><div> <ul> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/model.js~Model.html">Model</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/sequelize.js~Sequelize.html">Sequelize</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/transaction.js~Transaction.html">Transaction</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-DataTypes">DataTypes</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-Deferrable">Deferrable</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-QueryTypes">QueryTypes</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">associations</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/associations/base.js~Association.html">Association</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/associations/belongs-to-many.js~BelongsToMany.html">BelongsToMany</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/associations/belongs-to.js~BelongsTo.html">BelongsTo</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/associations/has-many.js~HasMany.html">HasMany</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/associations/has-one.js~HasOne.html">HasOne</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">errors</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~AccessDeniedError.html">AccessDeniedError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~AssociationError.html">AssociationError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~BaseError.html">BaseError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~ConnectionError.html">ConnectionError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~ConnectionRefusedError.html">ConnectionRefusedError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~ConnectionTimedOutError.html">ConnectionTimedOutError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~DatabaseError.html">DatabaseError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~EagerLoadingError.html">EagerLoadingError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~EmptyResultError.html">EmptyResultError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~ExclusionConstraintError.html">ExclusionConstraintError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~ForeignKeyConstraintError.html">ForeignKeyConstraintError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~HostNotFoundError.html">HostNotFoundError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~HostNotReachableError.html">HostNotReachableError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~InstanceError.html">InstanceError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~InvalidConnectionError.html">InvalidConnectionError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~OptimisticLockError.html">OptimisticLockError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~QueryError.html">QueryError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~SequelizeScopeError.html">SequelizeScopeError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~TimeoutError.html">TimeoutError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~UniqueConstraintError.html">UniqueConstraintError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~ValidationError.html">ValidationError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors/index.js~ValidationErrorItem.html">ValidationErrorItem</a></span></span></li> </ul> </div> </nav> <div class="content" data-ice="content"><div class="header-notice"> <div data-ice="importPath" class="import-path"><pre class="prettyprint"><code data-ice="importPathCode"></code></pre></div> <span data-ice="access">public</span> <span data-ice="kind">class</span> <span data-ice="source">| <span><a href="file/lib/associations/belongs-to-many.js.html#lineNumber57">source</a></span></span> </div> <div class="self-detail detail"> <h1 data-ice="name">BelongsToMany</h1> <div class="flat-list" data-ice="extendsChain"><h4>Extends:</h4><div><span><a href="class/lib/associations/base.js~Association.html">Association</a></span> &#x2192; BelongsToMany</div></div> <div class="description" data-ice="description"><p>Many-to-many association with a join table.</p> <p>When the join table has additional attributes, these can be passed in the options object:</p> <pre><code class="lang-js"><code class="source-code prettyprint">UserProject = sequelize.define(&apos;user_project&apos;, { role: Sequelize.STRING }); User.belongsToMany(Project, { through: UserProject }); Project.belongsToMany(User, { through: UserProject }); // through is required! user.addProject(project, { through: { role: &apos;manager&apos; }});</code> </code></pre> <p>All methods allow you to pass either a persisted instance, its primary key, or a mixture:</p> <pre><code class="lang-js"><code class="source-code prettyprint">Project.create({ id: 11 }).then(function (project) { user.addProjects([project, 12]); });</code> </code></pre> <p>If you want to set several target instances, but with different attributes you have to set the attributes on the instance, using a property with the name of the through model:</p> <pre><code class="lang-js"><code class="source-code prettyprint">p1.UserProjects = { started: true } user.setProjects([p1, p2], { through: { started: false }}) // The default value is false, but p1 overrides that.</code> </code></pre> <p>Similarly, when fetching through a join table with custom attributes, these attributes will be available as an object with the name of the through model.</p> <pre><code class="lang-js"><code class="source-code prettyprint">user.getProjects().then(function (projects) { let p1 = projects[0] p1.UserProjects.started // Is this project started yet? })</code> </code></pre> <p>In the API reference below, add the name of the association to the method, e.g. for <code>User.belongsToMany(Project)</code> the getter will be <code>user.getProjects()</code>.</p> </div> <div data-ice="see"><h4>See:</h4><ul><li><span><span><a href="class/lib/model.js~Model.html#static-method-belongsToMany">Model.belongsToMany</a></span></span></li></ul></div> </div> <div data-ice="methodSummary"><h2>Method Summary</h2><table class="summary" data-ice="summary"> <thead><tr><td data-ice="title" colspan="3">Public Methods</td></tr></thead> <tbody> <tr data-ice="target"> <td> <span class="access" data-ice="access">public</span> <span class="override" data-ice="override"></span> </td> <td> <div> <p> <span data-ice="name"><span><a href="class/lib/associations/belongs-to-many.js~BelongsToMany.html#instance-method-add">add</a></span></span><span data-ice="signature">(newAssociation(s): <span><span><a href="class/lib/model.js~Model.html">Model</a></span><span>[]</span></span> | <span><a href="class/lib/model.js~Model.html">Model</a></span> | <span><span>string</span><span>[]</span></span> | <span>string</span> | <span><span>number</span><span>[]</span></span> | <span>Number</span>, options: <span>Object</span>): <span>Promise</span></span> </p> </div> <div> <div data-ice="description"><p>Associate one ore several rows with <code>this</code>.</p> </div> </div> </td> <td> </td> </tr> <tr data-ice="target"> <td> <span class="access" data-ice="access">public</span> <span class="override" data-ice="override"></span> </td> <td> <div> <p> <span data-ice="name"><span><a href="class/lib/associations/belongs-to-many.js~BelongsToMany.html#instance-method-count">count</a></span></span><span data-ice="signature">(options: <span>Object</span>): <span>Promise</span>&lt;<span>Integer</span>&gt;</span> </p> </div> <div> <div data-ice="description"><p>Count everything currently associated with this, using an optional where clause.</p> </div> </div> </td> <td> </td> </tr> <tr data-ice="target"> <td> <span class="access" data-ice="access">public</span> <span class="override" data-ice="override"></span> </td> <td> <div> <p> <span data-ice="name"><span><a href="class/lib/associations/belongs-to-many.js~BelongsToMany.html#instance-method-create">create</a></span></span><span data-ice="signature">(values: <span>Object</span>, options: <span>Object</span>): <span>Promise</span></span> </p> </div> <div> <div data-ice="description"><p>Create a new instance of the associated model and associate it with this.</p> </div> </div> </td> <td> </td> </tr> <tr data-ice="target"> <td> <span class="access" data-ice="access">public</span> <span class="override" data-ice="override"></span> </td> <td> <div> <p> <span data-ice="name"><span><a href="class/lib/associations/belongs-to-many.js~BelongsToMany.html#instance-method-get">get</a></span></span><span data-ice="signature">(options: <span>Object</span>): <span>Promise</span>&lt;<span>Array</span>&lt;<span><a href="class/lib/model.js~Model.html">Model</a></span>&gt;&gt;</span> </p> </div> <div> <div data-ice="description"><p>Get everything currently associated with this, using an optional where clause.</p> </div> </div> </td> <td> </td> </tr> <tr data-ice="target"> <td> <span class="access" data-ice="access">public</span> <span class="override" data-ice="override"></span> </td> <td> <div> <p> <span data-ice="name"><span><a href="class/lib/associations/belongs-to-many.js~BelongsToMany.html#instance-method-has">has</a></span></span><span data-ice="signature">(instance(s): <span><span><a href="class/lib/model.js~Model.html">Model</a></span><span>[]</span></span> | <span><a href="class/lib/model.js~Model.html">Model</a></span> | <span><span>string</span><span>[]</span></span> | <span>String</span> | <span><span>number</span><span>[]</span></span> | <span>Number</span>, options: <span>Object</span>): <span>Promise</span>&lt;<span>boolean</span>&gt;</span> </p> </div> <div> <div data-ice="description"><p>Check if one or more instance(s) are associated with this.</p> </div> </div> </td> <td> </td> </tr> <tr data-ice="target"> <td> <span class="access" data-ice="access">public</span> <span class="override" data-ice="override"></span> </td> <td> <div> <p> <span data-ice="name"><span><a href="class/lib/associations/belongs-to-many.js~BelongsToMany.html#instance-method-remove">remove</a></span></span><span data-ice="signature">(oldAssociated: <span><a href="class/lib/model.js~Model.html">Model</a></span> | <span>String</span> | <span>Number</span>, options: <span>Object</span>): <span>Promise</span></span> </p> </div> <div> <div data-ice="description"><p>Un-associate one or more instance(s).</p> </div> </div> </td> <td> </td> </tr> <tr data-ice="target"> <td> <span class="access" data-ice="access">public</span> <span class="override" data-ice="override"></span> </td> <td> <div> <p> <span data-ice="name"><span><a href="class/lib/associations/belongs-to-many.js~BelongsToMany.html#instance-method-set">set</a></span></span><span data-ice="signature">(newAssociations: <span>Array</span>&lt;<span><a href="class/lib/model.js~Model.html">Model</a></span>|<span>String</span>|<span>Number</span>&gt;, options: <span>Object</span>): <span>Promise</span></span> </p> </div> <div> <div data-ice="description"><p>Set the associated models by passing an array of instances or their primary keys.</p> </div> </div> </td> <td> </td> </tr> </tbody> </table> </div> <div class="inherited-summary" data-ice="inheritedSummary"><h2>Inherited Summary</h2><table class="summary" data-ice="summary"> <thead><tr><td data-ice="title" colspan="3"><span class="toggle closed"></span> From class <span><a href="class/lib/associations/base.js~Association.html">Association</a></span></td></tr></thead> <tbody> <tr data-ice="target"> <td> <span class="access" data-ice="access">public</span> <span class="override" data-ice="override"></span> </td> <td> <div> <p> <span data-ice="name"><span><a href="class/lib/associations/base.js~Association.html#instance-member-associationType">associationType</a></span></span><span data-ice="signature">: <span>string</span></span> </p> </div> <div> <div data-ice="description"><p>The type of the association.</p> </div> </div> </td> <td> </td> </tr> <tr data-ice="target"> <td> <span class="access" data-ice="access">public</span> <span class="override" data-ice="override"></span> </td> <td> <div> <p> <span data-ice="name"><span><a href="class/lib/associations/base.js~Association.html#instance-member-source">source</a></span></span><span data-ice="signature">: <span><a href="class/lib/model.js~Model.html">Model</a></span></span> </p> </div> <div> </div> </td> <td> </td> </tr> <tr data-ice="target"> <td> <span class="access" data-ice="access">public</span> <span class="override" data-ice="override"></span> </td> <td> <div> <p> <span data-ice="name"><span><a href="class/lib/associations/base.js~Association.html#instance-member-target">target</a></span></span><span data-ice="signature">: <span><a href="class/lib/model.js~Model.html">Model</a></span></span> </p> </div> <div> </div> </td> <td> </td> </tr> </tbody> </table> </div> <div data-ice="methodDetails"><h2 data-ice="title">Public Methods</h2> <div class="detail" data-ice="detail"> <h3 data-ice="anchor" id="instance-method-add"> <span class="access" data-ice="access">public</span> <span data-ice="name">add</span><span data-ice="signature">(newAssociation(s): <span><span><a href="class/lib/model.js~Model.html">Model</a></span><span>[]</span></span> | <span><a href="class/lib/model.js~Model.html">Model</a></span> | <span><span>string</span><span>[]</span></span> | <span>string</span> | <span><span>number</span><span>[]</span></span> | <span>Number</span>, options: <span>Object</span>): <span>Promise</span></span> <span class="right-info"> <span data-ice="source"><span><a href="file/lib/associations/belongs-to-many.js.html#lineNumber599">source</a></span></span> </span> </h3> <div data-ice="description"><p>Associate one ore several rows with <code>this</code>.</p> </div> <div data-ice="properties"><div data-ice="properties"> <h4 data-ice="title">Params:</h4> <table class="params"> <thead> <tr><td>Name</td><td>Type</td><td>Attribute</td><td>Description</td></tr> </thead> <tbody> <tr data-ice="property" data-depth="0"> <td data-ice="name" data-depth="0">newAssociation(s)</td> <td data-ice="type"><span><span><a href="class/lib/model.js~Model.html">Model</a></span><span>[]</span></span> | <span><a href="class/lib/model.js~Model.html">Model</a></span> | <span><span>string</span><span>[]</span></span> | <span>string</span> | <span><span>number</span><span>[]</span></span> | <span>Number</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>A single instance or primary key, or a mixed array of persisted instances or primary keys</p> </td> </tr> <tr data-ice="property" data-depth="0"> <td data-ice="name" data-depth="0">options</td> <td data-ice="type"><span>Object</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>Options passed to <code>through.findAll</code>, <code>bulkCreate</code> and <code>update</code></p> </td> </tr> <tr data-ice="property" data-depth="1"> <td data-ice="name" data-depth="1">options.validate</td> <td data-ice="type"><span>Object</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>Run validation for the join model.</p> </td> </tr> <tr data-ice="property" data-depth="1"> <td data-ice="name" data-depth="1">options.through</td> <td data-ice="type"><span>Object</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>Additional attributes for the join table.</p> </td> </tr> </tbody> </table> </div> </div> <div class="return-params" data-ice="returnParams"> <h4>Return:</h4> <table> <tbody> <tr> <td class="return-type" data-ice="returnType"><span>Promise</span></td> </tr> </tbody> </table> <div data-ice="returnProperties"> </div> </div> </div> <div class="detail" data-ice="detail"> <h3 data-ice="anchor" id="instance-method-count"> <span class="access" data-ice="access">public</span> <span data-ice="name">count</span><span data-ice="signature">(options: <span>Object</span>): <span>Promise</span>&lt;<span>Integer</span>&gt;</span> <span class="right-info"> <span data-ice="source"><span><a href="file/lib/associations/belongs-to-many.js.html#lineNumber440">source</a></span></span> </span> </h3> <div data-ice="description"><p>Count everything currently associated with this, using an optional where clause.</p> </div> <div data-ice="properties"><div data-ice="properties"> <h4 data-ice="title">Params:</h4> <table class="params"> <thead> <tr><td>Name</td><td>Type</td><td>Attribute</td><td>Description</td></tr> </thead> <tbody> <tr data-ice="property" data-depth="0"> <td data-ice="name" data-depth="0">options</td> <td data-ice="type"><span>Object</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"></td> </tr> <tr data-ice="property" data-depth="1"> <td data-ice="name" data-depth="1">options.where</td> <td data-ice="type"><span>Object</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>An optional where clause to limit the associated models</p> </td> </tr> <tr data-ice="property" data-depth="1"> <td data-ice="name" data-depth="1">options.scope</td> <td data-ice="type"><span>String</span> | <span>Boolean</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>Apply a scope on the related model, or remove its default scope by passing false</p> </td> </tr> </tbody> </table> </div> </div> <div class="return-params" data-ice="returnParams"> <h4>Return:</h4> <table> <tbody> <tr> <td class="return-type" data-ice="returnType"><span>Promise</span>&lt;<span>Integer</span>&gt;</td> </tr> </tbody> </table> <div data-ice="returnProperties"> </div> </div> </div> <div class="detail" data-ice="detail"> <h3 data-ice="anchor" id="instance-method-create"> <span class="access" data-ice="access">public</span> <span data-ice="name">create</span><span data-ice="signature">(values: <span>Object</span>, options: <span>Object</span>): <span>Promise</span></span> <span class="right-info"> <span data-ice="source"><span><a href="file/lib/associations/belongs-to-many.js.html#lineNumber703">source</a></span></span> </span> </h3> <div data-ice="description"><p>Create a new instance of the associated model and associate it with this.</p> </div> <div data-ice="properties"><div data-ice="properties"> <h4 data-ice="title">Params:</h4> <table class="params"> <thead> <tr><td>Name</td><td>Type</td><td>Attribute</td><td>Description</td></tr> </thead> <tbody> <tr data-ice="property" data-depth="0"> <td data-ice="name" data-depth="0">values</td> <td data-ice="type"><span>Object</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"></td> </tr> <tr data-ice="property" data-depth="0"> <td data-ice="name" data-depth="0">options</td> <td data-ice="type"><span>Object</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>Options passed to create and add</p> </td> </tr> <tr data-ice="property" data-depth="1"> <td data-ice="name" data-depth="1">options.through</td> <td data-ice="type"><span>Object</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>Additional attributes for the join table</p> </td> </tr> </tbody> </table> </div> </div> <div class="return-params" data-ice="returnParams"> <h4>Return:</h4> <table> <tbody> <tr> <td class="return-type" data-ice="returnType"><span>Promise</span></td> </tr> </tbody> </table> <div data-ice="returnProperties"> </div> </div> </div> <div class="detail" data-ice="detail"> <h3 data-ice="anchor" id="instance-method-get"> <span class="access" data-ice="access">public</span> <span data-ice="name">get</span><span data-ice="signature">(options: <span>Object</span>): <span>Promise</span>&lt;<span>Array</span>&lt;<span><a href="class/lib/model.js~Model.html">Model</a></span>&gt;&gt;</span> <span class="right-info"> <span data-ice="source"><span><a href="file/lib/associations/belongs-to-many.js.html#lineNumber373">source</a></span></span> </span> </h3> <div data-ice="description"><p>Get everything currently associated with this, using an optional where clause.</p> </div> <div data-ice="properties"><div data-ice="properties"> <h4 data-ice="title">Params:</h4> <table class="params"> <thead> <tr><td>Name</td><td>Type</td><td>Attribute</td><td>Description</td></tr> </thead> <tbody> <tr data-ice="property" data-depth="0"> <td data-ice="name" data-depth="0">options</td> <td data-ice="type"><span>Object</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"></td> </tr> <tr data-ice="property" data-depth="1"> <td data-ice="name" data-depth="1">options.where</td> <td data-ice="type"><span>Object</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>An optional where clause to limit the associated models</p> </td> </tr> <tr data-ice="property" data-depth="1"> <td data-ice="name" data-depth="1">options.scope</td> <td data-ice="type"><span>String</span> | <span>Boolean</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>Apply a scope on the related model, or remove its default scope by passing false</p> </td> </tr> <tr data-ice="property" data-depth="1"> <td data-ice="name" data-depth="1">options.schema</td> <td data-ice="type"><span>String</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>Apply a schema on the related model</p> </td> </tr> </tbody> </table> </div> </div> <div class="return-params" data-ice="returnParams"> <h4>Return:</h4> <table> <tbody> <tr> <td class="return-type" data-ice="returnType"><span>Promise</span>&lt;<span>Array</span>&lt;<span><a href="class/lib/model.js~Model.html">Model</a></span>&gt;&gt;</td> </tr> </tbody> </table> <div data-ice="returnProperties"> </div> </div> <div data-ice="see"><h4>See:</h4><ul><li><span><span><a href="class/lib/model.js~Model.html#static-method-findAll">Model.findAll</a></span> for a full explanation of options</span></li></ul></div> </div> <div class="detail" data-ice="detail"> <h3 data-ice="anchor" id="instance-method-has"> <span class="access" data-ice="access">public</span> <span data-ice="name">has</span><span data-ice="signature">(instance(s): <span><span><a href="class/lib/model.js~Model.html">Model</a></span><span>[]</span></span> | <span><a href="class/lib/model.js~Model.html">Model</a></span> | <span><span>string</span><span>[]</span></span> | <span>String</span> | <span><span>number</span><span>[]</span></span> | <span>Number</span>, options: <span>Object</span>): <span>Promise</span>&lt;<span>boolean</span>&gt;</span> <span class="right-info"> <span data-ice="source"><span><a href="file/lib/associations/belongs-to-many.js.html#lineNumber463">source</a></span></span> </span> </h3> <div data-ice="description"><p>Check if one or more instance(s) are associated with this. If a list of instances is passed, the function returns true if <em>all</em> instances are associated</p> </div> <div data-ice="properties"><div data-ice="properties"> <h4 data-ice="title">Params:</h4> <table class="params"> <thead> <tr><td>Name</td><td>Type</td><td>Attribute</td><td>Description</td></tr> </thead> <tbody> <tr data-ice="property" data-depth="0"> <td data-ice="name" data-depth="0">instance(s)</td> <td data-ice="type"><span><span><a href="class/lib/model.js~Model.html">Model</a></span><span>[]</span></span> | <span><a href="class/lib/model.js~Model.html">Model</a></span> | <span><span>string</span><span>[]</span></span> | <span>String</span> | <span><span>number</span><span>[]</span></span> | <span>Number</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>Can be an array of instances or their primary keys</p> </td> </tr> <tr data-ice="property" data-depth="0"> <td data-ice="name" data-depth="0">options</td> <td data-ice="type"><span>Object</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>Options passed to getAssociations</p> </td> </tr> </tbody> </table> </div> </div> <div class="return-params" data-ice="returnParams"> <h4>Return:</h4> <table> <tbody> <tr> <td class="return-type" data-ice="returnType"><span>Promise</span>&lt;<span>boolean</span>&gt;</td> </tr> </tbody> </table> <div data-ice="returnProperties"> </div> </div> </div> <div class="detail" data-ice="detail"> <h3 data-ice="anchor" id="instance-method-remove"> <span class="access" data-ice="access">public</span> <span data-ice="name">remove</span><span data-ice="signature">(oldAssociated: <span><a href="class/lib/model.js~Model.html">Model</a></span> | <span>String</span> | <span>Number</span>, options: <span>Object</span>): <span>Promise</span></span> <span class="right-info"> <span data-ice="source"><span><a href="file/lib/associations/belongs-to-many.js.html#lineNumber681">source</a></span></span> </span> </h3> <div data-ice="description"><p>Un-associate one or more instance(s).</p> </div> <div data-ice="properties"><div data-ice="properties"> <h4 data-ice="title">Params:</h4> <table class="params"> <thead> <tr><td>Name</td><td>Type</td><td>Attribute</td><td>Description</td></tr> </thead> <tbody> <tr data-ice="property" data-depth="0"> <td data-ice="name" data-depth="0">oldAssociated</td> <td data-ice="type"><span><a href="class/lib/model.js~Model.html">Model</a></span> | <span>String</span> | <span>Number</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>Can be an Instance or its primary key, or a mixed array of instances and primary keys</p> </td> </tr> <tr data-ice="property" data-depth="0"> <td data-ice="name" data-depth="0">options</td> <td data-ice="type"><span>Object</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>Options passed to <code>through.destroy</code></p> </td> </tr> </tbody> </table> </div> </div> <div class="return-params" data-ice="returnParams"> <h4>Return:</h4> <table> <tbody> <tr> <td class="return-type" data-ice="returnType"><span>Promise</span></td> </tr> </tbody> </table> <div data-ice="returnProperties"> </div> </div> </div> <div class="detail" data-ice="detail"> <h3 data-ice="anchor" id="instance-method-set"> <span class="access" data-ice="access">public</span> <span data-ice="name">set</span><span data-ice="signature">(newAssociations: <span>Array</span>&lt;<span><a href="class/lib/model.js~Model.html">Model</a></span>|<span>String</span>|<span>Number</span>&gt;, options: <span>Object</span>): <span>Promise</span></span> <span class="right-info"> <span data-ice="source"><span><a href="file/lib/associations/belongs-to-many.js.html#lineNumber506">source</a></span></span> </span> </h3> <div data-ice="description"><p>Set the associated models by passing an array of instances or their primary keys. Everything that it not in the passed array will be un-associated.</p> </div> <div data-ice="properties"><div data-ice="properties"> <h4 data-ice="title">Params:</h4> <table class="params"> <thead> <tr><td>Name</td><td>Type</td><td>Attribute</td><td>Description</td></tr> </thead> <tbody> <tr data-ice="property" data-depth="0"> <td data-ice="name" data-depth="0">newAssociations</td> <td data-ice="type"><span>Array</span>&lt;<span><a href="class/lib/model.js~Model.html">Model</a></span>|<span>String</span>|<span>Number</span>&gt;</td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>An array of persisted instances or primary key of instances to associate with this. Pass <code>null</code> or <code>undefined</code> to remove all associations.</p> </td> </tr> <tr data-ice="property" data-depth="0"> <td data-ice="name" data-depth="0">options</td> <td data-ice="type"><span>Object</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>Options passed to <code>through.findAll</code>, <code>bulkCreate</code>, <code>update</code> and <code>destroy</code></p> </td> </tr> <tr data-ice="property" data-depth="1"> <td data-ice="name" data-depth="1">options.validate</td> <td data-ice="type"><span>Object</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>Run validation for the join model</p> </td> </tr> <tr data-ice="property" data-depth="1"> <td data-ice="name" data-depth="1">options.through</td> <td data-ice="type"><span>Object</span></td> <td data-ice="appendix"><ul><li>optional</li></ul></td> <td data-ice="description"><p>Additional attributes for the join table.</p> </td> </tr> </tbody> </table> </div> </div> <div class="return-params" data-ice="returnParams"> <h4>Return:</h4> <table> <tbody> <tr> <td class="return-type" data-ice="returnType"><span>Promise</span></td> </tr> </tbody> </table> <div data-ice="returnProperties"> </div> </div> </div> </div> </div> <footer class="footer"> Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(0.5.2)</span><img src="./image/esdoc-logo-mini-black.png"></a> </footer> <script src="script/search_index.js"></script> <script src="script/search.js"></script> <script src="script/pretty-print.js"></script> <script src="script/inherited-summary.js"></script> <script src="script/test-summary.js"></script> <script src="script/inner-link.js"></script> <script src="script/patch-for-local.js"></script> </body> </html>