javascript - Getting related data through object_2_object table with Sequelize -


i have pet object, belongs species through speciestopet.

i have following definitions sequelize.

const pet = sequelize.define(`pet`, {   id: {     type: sequelize.integer   }   ... })  const speciestopet = sequelize.define(`speciestopet`, {   speciesid: {     type: sequelize.integer   },   petid: {     type: sequelize.integer   } })  const species = sequelize.define(`species`, {   id: {     type: sequelize.integer   } }) 

now, pet.belongstomany(species, { as: 'species', through: speciestopet,foreignkey: 'petid', otherkey: 'speciesid' }) can species pet belongs to, want able pets in same species.

how can define relationship obtain values?

you should define species->pet relation:

species.belongstomany(pet, { as: 'pets', through: speciestopet}); 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -