While executing a DELETE operation, TypeORM mistakenly includes a superfluous AND clause in the final query

Edges Table Structure: id | from_node | to_node

Performing the operation:

node.id = 1
await getManager().delete(Edge, [{ from_node: node.id }, { to_node: node.id }]);

Generates the following 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]

However, the desired query is:

query: DELETE FROM "edges" WHERE ("from_node" = $1) OR ("to_node" = $2) -- PARAMETERS: [1,1]

The issue of the additional AND clause in the resulting query is puzzling.

In contrast, the following code functions correctly:

getManager()
.createQueryBuilder()
.delete()
.from(Edge)
.where([{ from_node: node.id }, { to_node: node.id }])
.execute();

Could someone offer an explanation for the discrepancy between the actual and intended outcomes of the getManager().delete operation?

Database: Postgres

Typeorm version: latest (0.2.24)

Answer №1

The reason this occurred is due to the fact that the Primary Composite Key for the Edges table consists of (from_node, to_node).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the method to retrieve a JSON property without using quotation marks?

I have a JSON document and I need to retrieve a specific property from it. Let's simplify this with an example: create table example_table(data text); insert into example_table(data) select '{"name":"Kevin"}'::json -> 'name'; ...

Using aliases in npm packages is not supported

I am working on creating an npm package that I want to use in another application. During development, I set a path in tsconfig for importing various modules instead of using a relative path. However, when I download my package into the test app, it is una ...

Switch up row values in an array and transform them into an object using SheetJS

I am struggling to format an array where each "Working Day" is represented as an object with specific details like index and start/end date. I need help manipulating the JSON data to achieve the desired structure. The package I'm currently using is: ...

Arrange an array within an Angular component

I'm in the process of organizing my list-component made with Angular Material. <div style="width:30%;"> <mat-nav-list matSort (matSortChange)="sortData($event)"> <th mat-sort-header="stuff.name">Name</th> ...

What is the process for exporting the reducer function and integrating it into the storeModule.forRoot within an Angular application?

Recently, I started delving into ngrx and decided to educate myself by going through the official documentation on their website ngrx.io. During this exploration, I came across a puzzling piece of code in one of their reducers. The file in question is cou ...

Designing the File and Folder Organization for Next.js Frontend and AWS Cloud Development Kit (CDK) Backend

When it comes to creating websites with serverless backends, I've been thinking about the best practices for folder structure. Currently, my setup includes a Next.js frontend and an AWS CDK backend. The way I've structured the folders has the bac ...

Obtain the map field from Firestore and retrieve the map data

My firestore database has a field with Maps of data, and I am struggling to retrieve this information using a cloud function in Node.js. Despite trying numerous solutions from Stack Overflow and Google, the code snippet below is the only one that gives me ...

Unable to retrieve data from localStorage in Next.js

Unable to access localStorage in Nextjs. Code works as expected without errors, but the terminal throws: ReferenceError: localStorage is not defined at MainGrid (./app/components/WeightDisplay/MainGrid.tsx:17:96) 8 | // Initialize states for prefe ...

Accessing TypeScript object in HTML using Angular 2

I'm curious if there is a way to create an isolated scope for an object in my HTML within a component in my Angular 2 application. For instance, imagine I have the following object in my component's TS file: private myObj = { nestedObj1: { ...

Integrating a new functionality into a sophisticated database search

My database includes a table for logging chat messages CREATE TABLE public.message_log ( id integer NOT NULL DEFAULT nextval('message_log_id_seq'::regclass), message text, from_id character varying(500), to_id character varying(500), m ...

Building a Multi-Language React Application with Real-Time Data

Is there a way for users to input data in their chosen language (English, French, German) and have that data saved in all three languages in the Database so they can view it based on their language selection? I've experimented with React-Intl and I18 ...

In order for the argument to be valid, it is

Transitioning to Typescript has brought me immense joy for various reasons. While exploring its benefits, I encountered a challenge related to verifying if an argument passed to a function extends another class. Here is an example scenario: class Foo { ...

The child component displays an error when input is entered, but occasionally it successfully loads

Currently, I am encountering an issue with passing an object from a parent component to a child component in Angular. Whenever I run the command ng serve, an error is thrown stating that the passed object cannot be found. However, on occasions when I save ...

Utilizing .js file alongside declaration files .d.ts in Angular: A guide

I am facing an issue with my Angular 7 app where I need to include some typed JS constants from outside of the project. These constants are essential for the AngularJS app and need to be kept in a separate js file. I have defined a new path in the tsconfig ...

What is the method for dynamically altering attributes using a directive?

I am currently working on dynamically assigning attributes to HTML tags (such as Select, Button, or Input) within a switch statement. However, I'm a bit stuck and would appreciate any better ideas or suggestions you may have. My goal is to identify w ...

Encountered Typescript issue when utilizing typed forms in Angular

Below is the interface I am working with: export interface ILoginDto { email: string; password: string; } Here is a snippet of the relevant code from the component: import { FormBuilder, FormGroup, Validators } from '@angular/forms'; export ...

Unable to transform column into JSON within Postgresql due to an invalid token "top"

My current challenge involves converting a column in my Postgresql 9.4.4 database from VARCHAR to JSON. This specific column holds both text and null values. Despite my efforts, I keep encountering an error message that says Token "top" is invalid., leavi ...

Guide to specifying an explicit return type annotation for a recursive closure with JSDoc

In a project that utilizes vanilla JavaScript and type checking with tsc through JSDoc annotations, I have encountered a challenging use case. There is a function that returns another function, which may recursively call itself while also reassigning certa ...

I am in the process of transitioning my JSX website to TSX and am struggling to figure out the proper placement of my type definitions

As the title suggests, I am in the process of migrating an application that I developed using the Google Maps API for rendering maps. In this app, I display information on maps and include functionality to zoom in when a user clicks on something. The erro ...

Retrieve the imported object by referencing the environment

Within my TypeScript Node application, I am looking to access the exported object that corresponds to my NODE_ENV variable. config.ts const test: { [index: string]: any } = { param1: "x", param2: { name: "John" } } const dev: { [index ...