简体   繁体   中英

Create with associated instances - Sequelize

Using sequelize ORM you can create with association in one swoop:

Product.create({
id: 1,
  title: 'Chair',
  Tags: [
    { name: 'Alpha'},
    { name: 'Beta'}
  ]
}, {
  include: [ Tag ]
})

My question is: How would I go about this when I have to work with an array of an arbitrary number of elements (here Tags) passed along?

The question is not clear. But if you mean what if you have many attributs like Tags which are associations, maybe what you are looking for is:

include: [{
    all: true
}]

or

include: [{
    all: true,
    include: [{
        all: true
    }]
}]

For nested elements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM