-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Labels
type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type
Description
Setting through attributes to [] doesn't exclude the id columns from being selected.
The model query:
componentsPromise = models.Component.findAll({
include: [{
attributes: [],
model: models.Platform,
through: {
attributes: []
},
as: 'platforms',
where: {
id: {
in: ids
}
}
}],
group: ['component.id'],
having: ['COUNT(?) = ?', 'component.id', ids.length]
})
Defining the association:
Component.belongsToMany(Platform, {
through: 'platform_components',
as: 'platforms',
foreignKey: 'component_id',
otherKey: 'platform_id'
});
Platform.belongsToMany(Component, {
through: 'platform_components',
as: 'components',
foreignKey: 'platform_id',
otherKey: 'component_id'
});
The result query:
SELECT
"component"."id",
"component"."component_name",
"component"."component_type",
"component"."created_at",
"component"."updated_at",
"platforms.platform_components"."platform_id" AS "platforms.platform_components.platform_id",
"platforms.platform_components"."component_id" AS "platforms.platform_components.component_id"
FROM "components" AS "component" INNER JOIN
("platform_components" AS "platforms.platform_components" INNER JOIN "platforms" AS "platforms"
ON "platforms"."id" = "platforms.platform_components"."platform_id")
ON "component"."id" = "platforms.platform_components"."component_id" AND "platforms"."id" IN ('1', '2', '3')
GROUP BY "component"."id", "platforms.platform_components.platform_id", "platforms.platform_components.component_id"
HAVING COUNT('component.id') = 3;
This is a major problem in postgres, as this query will fail because the group by must include the through table primary keys, which subsequently makes the query not function.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type