'Why is the route name included in the query?
I really can't get my head around this problem. I have a temporary fix which is totally moving the route.
Here are the models in question
Activity.belongsToMany(User, {through: "activity_completion", as: "member"});
User.belongsToMany(Activity, {through: "activity_completion", as: "member"});
The association works, I have appropriate unit test.
This is the faulty code
router.get("/subscriptions", auth, async (req, res) => {
try {
await db.sequelize.sync();
const listOfActivities = await Activity.findAll({
include: {
model: User, as: 'member',
attributes: ['firstName', 'lastName', 'role'],
},
where: { expertId: req.decoded.userId },
});
res.json({ "data": listOfActivities });
} catch (e) {
res.json({ "error": e.message });
}
})
This works fine ONLY if I move the code to another route. In the current route, it always gives me this error on query
ERROR: INVALID INPUT SYNTAX FOR TYPE INTEGER "subscriptions"
In any case, the damn sequelize tries to find an Activity which has "subscriptions" as the id
db-1 2022-05-16 14:50:33.602 UTC (40) ERROR: invalid input syntax for type integer: "enrollment" at character 259
db-1 2022-05-16 14:50:33.602 UTC [40] STATEMENT: SELECT ..(misc).. FROM "activities" AS "Activity" WHERE ("Activity"."id" = 'subscriptions' )
Note that if I change the route name, for example as "enrollments"
db-1 2022-05-16 14:50:33.602 UTC [40] STATEMENT: SELECT ..(misc).. FROM "activities" AS "Activity" WHERE ("Activity"."id" = 'enrollments' )
And note that once I changed the route, it works fine. I moved it from IP/activities/enrollments to IP/enrollments and it works perfectly.
Do you have any idea what this could be? Thanks in advance everyone
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
