简体   繁体   English

使用关联实例创建-Sequelize

[英]Create with associated instances - Sequelize

Using sequelize ORM you can create with association in one swoop: 使用sequelize ORM,您可以一键创建关联:

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. 对于嵌套元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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