-
Notifications
You must be signed in to change notification settings - Fork 642
Open
Description
While working with ObjectionJS on a project, I encountered a case where the bindings in the generated query were inverted.
Dependencies versions:
- objection 3.1.5
- knex 3.1.0
This bug seems to only occur
- on a
deletequery - using a modifier
- inside a
joinRelated - that adds a binding to the SQL query
- inside a
I've prepared a full reprodution project in this repository, it contains the database schema, the models and the code. Here is a quick overview:
- Three models (
Person,Tagand a relationPersonTagthat links them) - The
Personmodel has afavoriteattribute and acategoryattribute
Person PersonTag Tag
________ <- _________ -> ____
id personId id
name tagId tag
category
favorite
I want to delete all the links (PersonTag) for favorite persons having a specific category. For reasons outside the scope of this issue, I use a modifier on my joinRelated clause instead of a where clause. I start by selecting the objects to be deleted
await PersonTagModel.query()
.joinRelated("person(favoriteFilter)")
.modifiers({
favoriteFilter: favoritePersonModifier
})
.where("person.category", "Follower")
.debug()
And the resulting query is correct:
- sql:
'select `personTag`.* from `personTag` inner join (select `person`.* from `person` where `favorite` = ?) as `person` on `person`.`id` = `personTag`.`personId` where `person`.`category` = ?' - bindings:
[ 1, 'Follower' ]
Then I change this to a delete query:
await PersonTagModel.query()
.joinRelated("person(favoriteFilter)")
.modifiers({
favoriteFilter: favoritePersonModifier
})
.where("person.category", "Follower")
.delete()
.debug()
And the bindings are inverted:
- sql:
'delete `personTag` from `personTag` inner join (select `person`.* from `person` where `favorite` = ?) as `person` on `person`.`id` = `personTag`.`personId` where `person`.`category` = ?' - bindings:
[ 'Follower', 1 ]
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels