gpt4 book ai didi

node.js - 在 Sequelize 中使用左连接复制行

转载 作者:行者123 更新时间:2023-12-03 22:26:23 25 4
gpt4 key购买 nike

我在 Sequelize postgress by limit 和 offset 中使用 LEFT JOIN。
当我更改下一页的限制和偏移量时,最后一页的结束行重复
在下一页的第一行。

关系:

 service.hasMany(servicePicture, { foreignKey: 'ServiceID', targetKey: 'ServiceID' });
servicePicture.belongsTo(service, { foreignKey: 'ServiceID', targetKey: 'ServiceID' });

我使用:
models.Service.findAll({
attributes: attributes,
where: whereClause,

include: {

model: models.ServicePicture ,
attributes:[
'ServicePictureID',
'ServicePicturePath'
],
where: {IsDeleted : false},
required:false,

} ,

subQuery:false,
offset: startRowIndex,
limit: recordCount,

})
.then(serviceModels =>{
resolve(serviceModels);})

最佳答案

在查询中使用 distinct:true

models.Service.findAll({
attributes: attributes,
where: whereClause,

include: {

model: models.ServicePicture ,
attributes:[
'ServicePictureID',
'ServicePicturePath'
],
where: {IsDeleted : false},
required:false,

} ,

subQuery:false,
offset: startRowIndex,
limit: recordCount,
distinct:true // add this distinct here

})
.then(serviceModels =>{
resolve(serviceModels);})

关于node.js - 在 Sequelize 中使用左连接复制行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59244684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com