表结构: { id: { type: DataTypes.INTEGER.UNSIGNED, autoIncrement: true, primaryKey: true, allowNull: false }, enid: { type: DataTypes.STRING(100), unique: true, allowNull: false }, name: { type: DataTypes.STRING(100), unique: true, allowNull: false }, update_time: { type: DataTypes.DATE, defaultValue: DataTypes.NOW, allowNull: false }, index: { type: DataTypes.TINYINT.UNSIGNED, defaultValue: 0, allowNull: false }, pid: { type: DataTypes.INTEGER.UNSIGNED, allowNull: true }, logo: { type: DataTypes.STRING(200), allowNull: true }, view: { type: DataTypes.INTEGER.UNSIGNED, defaultValue: 0, allowNull: false }, intro: { type: DataTypes.STRING(1000), allowNull: false }, } 同步到数据库后: "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241003/781b805c7006d0337b475a81273f686e.png) 第一次插入数据正常: "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241003/7efec3d16617fd1d02f46397473b0c21.png) "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241003/d2c5e668a7784e2ce539a1b62da11024.png) 插入第二条数据就会报错: (数据: { enid: 'ddfffff', name: 'Ddfffff', index: 7, pid: null, intro: 'aaaaaaaaaaaaaaaaa' }) "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241003/dc3f88ab7d02ff578bd27d6811b95a46.png) 大佬们看看是哪里的问题?? 第二次插入数据的时候如果添加id: 1,就能插入成功,否则失败!
有两张表 "article" 与 "tag" 多对多关联 ArticleSchema.belongsToMany(CategorySchema, { through: { model: ArticleCategory, unique: false // 取消联合主键的约定 }, as: 'category', foreignKey: 'articleId', constraints: false }) CategorySchema.belongsToMany(ArticleSchema, { through: { model: ArticleCategory, unique: false }, as: 'article', foreignKey: 'categoryId', constraints: false }) 我现在需要通过"tag"来筛选关联的"article"应该怎么写呢 尝试了在 "where" 中查询,但是关联的属性是报错的,在 "include" 中来做筛选的话,将 "tag" 也进行了筛选 https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241211/e5f9e201f2237660bdce92f0ffa8e123.png 想要得到的结果就是 "tag" 传入 "10" 或者 "11" 或者 "10和11" "tag" 都能返回图中的结果 有什么办法可以很简单的拿到呢
代码如下: let queryRes = await models.wb_user_chain.findAll( {attributes: [ 'id', 'companyName' ], include: [{ model: models.wb_user_users, attributes: ['status'], where: { userID: sequelize.col('companyID') } }], where: { userID: req.user.userID }, order: [['id', 'ASC']], raw: true}); 两个表的关联关系如下: wb_user_chain.belongsTo(wb_user_users, { foreignKey: 'companyID' }); wb_user_users.hasMany(wb_user_chain); 结果如下: { "code": 0, "data": { "companyList": [ { "id": 2, "companyName": "name", "wb_user_user.status": 2 } } } 我并没有在任何地方设置过wb_user_users这个表的别名,但是结果里却出现了wb_user_user这个别名,我要怎么不返回status字段的前缀wb_user_user?