You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
has[Association]() makes a complete INNER JOIN SELECT - should be lightweight confirmation, proof and solution #10514
Change internal behavior of has[Association]() method calls to use options object { attributes: [], joinTableAttributes: [] } so that this operation does not perform such a heavy query.
Output, either JSON or SQL
Dialect: postgres (but I believe any should be affected) Dialect version: 9.6.10 Database version: 9.6.10 Sequelize version: 4.43.0 Tested with latest release: No (If yes, specify that version)
Note :Your issue may be ignored OR closed by maintainers if it's not tested against latest version OR does not follow issue template.
/** * Check if one or more instance(s) are associated with this. If a list of instances is passed, the function returns true if _all_ instances are associated *X * @param {<Model>} sourceInstance source instance to check for an association with * @param {<Model>|<Model>[]|string[]|string|number[]|number} [instances] Can be an array of instances or their primary keys * @param {Object} [options] Options passed to getAssociations * * @returns {Promise<boolean>} */has(sourceInstance,instances,options){constwhere={};if(!Array.isArray(instances)){instances=[instances];}options=Object.assign({raw: true},options,{scope: false,Xattributes: [],XjoinTableAttributes: [],});where[Op.or]=instances.map(instance=>{if(instanceinstanceofthis.target){returninstance.where();}return{[this.target.primaryKeyAttribute]: instance};});options.where={[Op.and]: [where,options.where]};returnthis.get(sourceInstance,options).then(associatedObjects=>associatedObjects.length===instances.length);}
sorry I don't know how to make contributions to open source projects. if anyone can tell me the steps I'd be happy to introduce this fix.
changed the title [-]has[Association] makes a complete INNER JOIN SELECT - should be lightweight[/-][+]has[Association] makes a complete INNER JOIN SELECT - should be lightweight confirmation, proof and solution[/+]on Mar 7, 2019
changed the title [-]has[Association] makes a complete INNER JOIN SELECT - should be lightweight confirmation, proof and solution[/-][+]has[Association]() makes a complete INNER JOIN SELECT - should be lightweight confirmation, proof and solution[/+]on Mar 7, 2019
Activity
the-vampiire commentedon Mar 6, 2019
where to change: lib/associations/belongs-to-many.js line 476
attributes: [], joinTableAttributes: []@parammodified:
sorry I don't know how to make contributions to open source projects. if anyone can tell me the steps I'd be happy to introduce this fix.
[-]has[Association] makes a complete INNER JOIN SELECT - should be lightweight[/-][+]has[Association] makes a complete INNER JOIN SELECT - should be lightweight confirmation, proof and solution[/+][-]has[Association] makes a complete INNER JOIN SELECT - should be lightweight confirmation, proof and solution[/-][+]has[Association]() makes a complete INNER JOIN SELECT - should be lightweight confirmation, proof and solution[/+]the-vampiire commentedon Mar 9, 2019
@sushantdhiman thanks!