Friday, 17 July 2020

Why does Sequelize [Op.Or]: emptyArray returns all table-entires?

To give context: I was programming my NODE-JS app, which uses sequelize. I have this codesnippet:projectModel.findAll({ where: { groupID: { [Op.or]: allGroups } }, raw: true }) allGroups is initialized with an empty array (like this var allGroups = []), and is then populated with the groupIDs I found for the current User.So if I found any groupIDs, the allGroups-array stayed empty and I expected the codesnippet to return no projects at all, since none of the (zero) GroupIDs in allGroups matchend a groupID in the database-table.Instead, i got ALL entries in the project table.Why is sequelize doing that?I fixed it with initalizing the allGroups-array with an null-object, now it works fine in every case

Submitted July 17, 2020 at 11:24PM by TheLegendOfTrain

No comments:

Post a Comment