Repository navigation
Description
What are you doing?
I am trying to exclude association's fields from select statement in sequelize, since I am doing aggregation I don't want to include them in the group by
testSummary(req, res) {
return category.findAll({
attributes: ['name', 'CapabilityTypes.name', [sequelize.fn('COUNT', sequelize.col('CapabilityTypes.name')), 'Count']],
where: {
deleted: false
},
include: [{
model: capabilityType,
attributes: [],
include: [{
model: capability,
attributes: [],
through: {
attributes: []
},
}]
}],
group: ['Category.name','CapabilityTypes.name'],
raw:true
})
.then(summary => {
res.status(200).json({
summary: summary,
success: true,
message: "Successfully retrieved."
})
}).catch((error) => {
console.log(error);
res.status(500).send({
success: false,
message: "Failed to retrieve."
})
})
}
What do you expect to happen?
I expect attributes from the join table that highlighted in the raw select statement below NOT show up, and I don't want them in the group by
What is actually happening?
SELECT
"Category"."name",
"CapabilityTypes"."name",
COUNT("CapabilityTypes"."name") AS "Count",
"CapabilityTypes -> Capabilities -> CapabilityTypeMatrix"."capabilityId" AS "CapabilityTypes.Capabilities.CapabilityTypeMatrix.capabilityId",
"CapabilityTypes -> Capabilities -> CapabilityTypeMatrix"."capabilityTypeId" AS "CapabilityTypes.Capabilities.CapabilityTypeMatrix.capabilityTypeId"
FROM
"public"."Category" AS "Category"
LEFT OUTER JOIN
"public"."CapabilityType" AS "CapabilityTypes"
ON "Category"."id" = "CapabilityTypes"."categoryId"
LEFT OUTER JOIN
(
"public"."CapabilityTypeMatrix" AS "CapabilityTypes -> Capabilities -> CapabilityTypeMatrix"
INNER JOIN
"public"."Capability" AS "CapabilityTypes -> Capabilities"
ON "CapabilityTypes -> Capabilities"."id" = "CapabilityTypes -> Capabilities -> CapabilityTypeMatrix"."capabilityId"
)
ON "CapabilityTypes"."id" = "CapabilityTypes -> Capabilities -> CapabilityTypeMatrix"."capabilityTypeId"
WHERE
"Category"."deleted" = false
GROUP BY
"Category"."name",
"CapabilityTypes"."name";
__Dialect: postgres
__Database version: 9.4
__Sequelize version:4.38.0, also tried 4.37.10 and latest 4.41
Tested with latest release: No (If yes, specify that version)
Note : Your issue may be ignored OR closed by maintainers if it's not tested against latest version OR does not follow issue template.
Activity
wl1711 commentedon Nov 8, 2018
commenting or uncommenitng the hightlighted part does make a different in the JSON result, but the raw query it genertated is exactly the same.
stale commentedon Feb 7, 2019
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂
hocinekhen commentedon Sep 27, 2019
this still an issue, I use Sequelize v5.19.1, it just hides the attributes but the attributes still shown in select statement