В теории такой запрос в sequelize должен работать
const data = await db.Event.findAll(
{
attributes: ['TypeEventId'],
include: [{
model: db.YearOfEventDefault,
attributes: ['year', [db.sequelize.fn('sum', db.sequelize.col('money')), 'total_money'], [db.sequelize.fn('sum', db.sequelize.col('count')), 'total_count']],
group: ['year'],
}],
group: ['TypeEventId', '"YearOfEventDefaults.year"'],
});
по моему мнению он должен быть равен следующему запросу
SELECT
"Event"."TypeEventId",
"YearOfEventDefaults"."year" AS "YearOfEventDefaults.year",
sum("money") AS "YearOfEventDefaults.total_money",
sum("count") AS "YearOfEventDefaults.total_count"
FROM "Events" AS "Event"
LEFT OUTER JOIN "YearOfEventDefaults" AS "YearOfEventDefaults"
ON "Event"."id" = "YearOfEventDefaults"."EventId"
AND ("YearOfEventDefaults"."deletedAt" IS NULL)
WHERE ("Event"."deletedAt" IS NULL)
GROUP BY "TypeEventId" , "YearOfEventDefaults.year";
но туда прописываются лишние id которых я специально хотел избежать
SELECT
"Event"."id", // <------ вот это лишнее
"Event"."TypeEventId",
"YearOfEventDefaults"."id" AS "YearOfEventDefaults.id", // <------ вот это лишнее
"YearOfEventDefaults"."year" AS "YearOfEventDefaults.year",
sum("money") AS "YearOfEventDefaults.total_money",
sum("count") AS "YearOfEventDefaults.total_count"
FROM "Events" AS "Event"
LEFT OUTER JOIN "YearOfEventDefaults" AS "YearOfEventDefaults"
ON "Event"."id" = "YearOfEventDefaults"."EventId"
AND ("YearOfEventDefaults"."deletedAt" IS NULL)
WHERE ("Event"."deletedAt" IS NULL)
GROUP BY "TypeEventId", "YearOfEventDefaults"."year";
Что нужно написать чтобы от них избавится?