You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
add* and set* methods from belongsToMany raise SequelizeEmptyResultError if rejectOnEmpty is set to true in the target model #9531
Note: The problem is reproductible with a classic (non self reference) belongsToMany association
What do you expect to happen?
It should create an association in the users_blacklists table with User instances I pass to methods addBlacklist, addBlacklists or setBlacklists, like :
user.addBlacklists([userBlocked1,userBlocked2]).then(()=>{// saved!})// Where `user`, `userBlocked1` and `userBlocked2` are valid existing `User` instances
What is actually happening?
I get a SequelizeEmptyResultError instead when using those methods.
The SQL output shows that Sequelize is trying to do a SELECT instead of an INSERT whether I use addBlacklist, addBlacklists or setBlacklists, which obviously explains the SequelizeEmptyResultError since Sequelize did not insert those entries in the table yet.
After some research and digging in sequelize's code, it appears you are doing a findAll first to check if the added instances already exist in the join table :
If the option rejectOnEmpty is set to true in the target model definition, this findAll raise the SequelizeEmptyResultError error.
Now, this is really weird since this is the join table which is queried here, not the target table having this option defined, so it shouldn't raise, but even if it does, you should catch it.
I can disable the rejectOnEmpty for now to bypass this issue, but this is triggering side effects in my code I'm not happy with.
I'll try to make a quick and simple PR for this issue unless you can quickly fix this problem.
changed the title [-]Unexpected belongsToMany behavior with self references[/-][+]add* and set* methods from belongsToMany raise SequelizeEmptyResultError if rejectOnEmpty is set to true in the target model[/+]on Jun 13, 2018
Activity
[-]Unexpected belongsToMany behavior with self references[/-][+]add* and set* methods from belongsToMany raise SequelizeEmptyResultError if rejectOnEmpty is set to true in the target model[/+]