node.js - Sequelize, Issue with filtering on the join model for belongsToMany associations -


the sequelize docs suggest can filter query on join table attributes using following params on options object: [options.include[].through.where]

i've tried use formulation in code below , found filtering not work.

model user , model network associated through join table network-affiliations, has additional attribute (boolean) 'confirmed'. can't seem write query returns confirmed networks associated user.

my code excerpted below.

const network_affiliations = db.define('network_affiliations', {     networkemail: { type: sequelize.string },     confirmed: { type: sequelize.boolean } }, {     freezetablename: true,     defaultscope: {         where: {             confirmed: true         }     }, });  // user belongs many networks , networks belong many users (join table) user.belongstomany(network, { through: network_affiliations }); network.belongstomany(user, { through: network_affiliations });  //querying find 1 user, including confirmed networks user.findone({             where: {                 email: req.body.email             },             include: [{ model: network, through: { network_affiliations: { where: { confirmed: true } } } }]         }) 

i expect query return user instance associated networks -- networks confirmed: true. instead i'm getting networks associated user (including confirmed: false , confirmed: undefined).

as can see in above code, tried setting defaultscope join table ({confirmed: true}). appears not anything.

i've tried user.findall query otherwise identical, , not work.

what missing, or sequelize not working here?

sequelize version: "^3.30.4"


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -