I am using Sequelize findAndCountAll()
for my website's pagination.
The findAndCountAll()
returns the total items number(3990
) is bigger than the actual returned data number (3770
).
Does anyone know how to make the findAndCountAll()
returns the total items number which is the same as the actual data returned?
The table which I use findAndCountAll()
queries including two other tables, like the code below:
const patientModel: IIncludeOptions = {
model: Patient,
attributes: ["deviceId", "firstName", "lastName"],
};
const deviceModel: IIncludeOptions = {
model: Device,
required: true,
attributes: ["deviceId", "deviceSerialNumber"],
include: [patientModel],
};
const eventCodeModel: IIncludeOptions = {
model: EventCode,
required: true,
attributes: ["name"],
};
const opts: IFindOptions = {
...pageSizeLimit,
offset : offsetNum,
attributes: ["id", "deviceId", "eventId", "dispatchedAt", "message", "createdAt"],
include: [
deviceModel,
eventCodeModel,
],
order: sortBy,
};
const resCount = await DeviceEvent.findAndCountAll(opts).then((response) => {
const totalItems = response.count;
return {
totalItems,
currentPage: page || 1,
};
});