Edges
Table Structure:
id | from_node | to_node
Operation:
node.id = 1
await getManager().delete(Edge, [{ from_node: node.id }, { to_node: node.id }]);
Results in: the query
DELETE FROM "edges" WHERE (("from_node" = $1 AND "to_node" = $2) OR ("from_node" = $3 AND "to_node" = $4)) -- PARAMETERS: [1,null,null,1]
Whereas the query which I want is:
query: DELETE FROM "edges" WHERE ("from_node" = $1) OR ("to_node" = $2) -- PARAMETERS: [1,1]
I have no idea why the extra AND
clause is being added to the resultant query.
On the other hand this code work perfectly fine:
getManger()
.createQueryBuilder()
.delete()
.from(Edge)
.where([{ from_node: node.id }, { to_node: node.id }])
.execute();
Can someone please explain the reason for mismatch in the actual and desired result in the getManager().delete
operation?
DB: Postgres
Typeorm version: latest (0.2.24)
This was happening because for Edges
table the Primary Composite Key is (from_node, to_node)
.