Typeorm fails to recognize the @column name assigned to certain columns

I am facing an issue while attempting to remove some data records from an entity. Typeorm does not seem to be utilizing the @Column definition of the entity, leading to an invalid SQL query:

@Entity('table')
export class TableEntity implements Table {
  @Column({ name: 'user_id' })
  @PrimaryColumn()
  userId: number;
   ...
}
this.repository.delete({
   userId: 1
})
DELETE FROM "table" WHERE "userId" = $1

instead of

DELETE FROM "table" where "user_id" = $1

which was my expectation. Can someone explain why this is happening?

Answer №1

The author of this post may have resolved the issue long ago, but for those who found it via Google like myself:

Using @PrimaryColumn() will overwrite any information set by @Column().

Therefore, instead of doing this:

@Column({ name: 'user_id' })
@PrimaryColumn()
userId: number;

You should do this:

@PrimaryColumn({ name: 'user_id' })
userId: number;

Happy coding everyone!

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

I am looking to save the data entered in an HTML form directly into a JSON file within the webpage

I am currently storing the value in an array on the server, but I would like to store it only on the client side within the webpage. I want to write the form data from the HTML form into a JSON file that remains on the page itself and is not sent to the ...

Is there a way to animate without specifying a duration?

Exploring the capabilities of the Animated component in react-native, I came across the powerful Animated.timing(); function which operates within a specific duration defined as duration: 2000,. While duration is useful in certain scenarios, I found myself ...

Problem with Jquery Ajax, failing to recognize option values

Hello everyone, please review the code snippet below... $.fn.myajax = function (options) { var defaults = { my_event: "", my_url: "", my_data: "", } var o = {}; var mydata = options.my_data; $.extend(o, default ...

Issues arise with Typescript Intellisense in Visual Studio Code causing it to stop functioning

I'm currently exploring the world of building desktop applications using Electron and Typescript. After selecting Visual Studio Code as my IDE, everything was going smoothly and I managed to successfully load a sample HTML file into Electron. However ...

I'm facing an issue with running npm start on my react project ever since I installed babel-cli

YTGJAI@DESKTOP-DOAIF41 MINGW64 ~/Desktop/LYNDA MERN/Exercise Files/Ch02/02_01/start/dist $ npm start [email protected] start c:\Users\mctumbaga\Desktop\LYNDA MERN\Exercise Files\Ch02\02_01\start httpster -d ...

Issue with the SQL Server 2016 sp_execute_external_script and its integration with R

Exploring the integration of SQL Server 2016 with R in-database on Windows 10 has been a fascinating journey. I meticulously followed the installation steps for all components and scripts. However, I now find myself pondering the following questions: Wher ...

Discovering the central point within an SVG path

I am currently working with a path that is part of a group and using Jquery to locate the specific path. My goal is to find the midpoint of that path. I came across an example here. However, when attempting to use .getTotalLength(); or .getPointAtLength(), ...

Generating an XML document composed of Header, Detail, and Trailer segments based on the provided XSD schema

I have been tasked with creating an XML file that includes a header, detail, and trailer section. The data for this XML will be retrieved from a database using TSQL. The provided data specifications include sample XSD and XML files. My current XML file str ...

What steps can be taken to ensure a protractor test fails when a function does not succeed

For debugging my protractor test cases, I have developed helper methods. One of the key functions is waiting for an element to be clickable. To ensure that Protractor has enough time to find and enable the element, I am implementing a loop. However, in cas ...

Understanding Javascript Scoping

<html> <head> <title></title> <script type="text/javascript"> var x = 1; function y() { x = 10; return; function z() {} } </script> </head> <body> <script type="text/javascri ...

Display a photo transitioning from black and white to color in a loading fashion, moving from left to right

Is there a way to enhance the clarity of the question's title? I have an interesting effect where text starts off in grey color and then transitions to black using keyframes in CSS with the animate property. I'm curious about how I can achieve ...

Having trouble entering text into a textbox in Reactjs when the state is empty

I am currently working on integrating a newsletter submit form using Reactjs/nextjs. However, I am facing an issue where once I submit the form, I am unable to type anything in the textbox. I have tried making the "state" empty but it did not resolve the ...

Using Express and Node JS to upload a text file into MongoDB

I have a simple text file that I want to upload and save in my MongoDB database. While I can successfully upload the file using basic HTML code, I am struggling with storing it. Here is what my file.html looks like: <!DOCTYPE html> <html> < ...

The tabs are visible in the drawer, but the transition is not occurring

I am a beginner when it comes to using material ui. After clicking on advanced sports search, a drawer pops up. I have been trying to incorporate tabs in the drawer, but every time I click on tab two, the drawer closes. In reality, it should switch between ...

Setting up Redis for session store in the right way involves a few key steps

I have been attempting to configure Redis Store in the following manner: var express = require('express'); var app = express(); ....... ....... var session = require('express-session'); var redis = require("redis").createClient(); var ...

various arbitrary visuals on an HTML5 canvas

I am attempting to randomly draw multiple images from an array on a canvas, but I'm struggling with iterating through the array and drawing them when the draw() function is called within a for loop. Here's my current code: // Call Draw particle ...

How can I display a modal exclusively on a specific screen size?

Having a situation where two components are involved. The first component has an ng-click function that triggers a modal containing the second component. Currently, everything is working smoothly. However, the issue arises when the modal should only open a ...

Issues with invoking C# event through ajax communication

Whenever I click the Button, an Ajax method is called that triggers a webmethod on the server side. However, currently, the [WebMethod] is not being executed as expected. Below are the snippets of both the Ajax and server-side code: Ajax code $(document ...

Dynamic Bootstrap Modal for Enhanced User Experience

We have been racking our brains over this issue. Whenever the Bootstrap modal is opened, it shifts the background of the page to the top and then returns it back when closed. Is there any way to prevent this movement? So far, we have updated to Bootstra ...

Discover the steps to transform the elements within an array to a particular structure

I am working with an API that has the following structure: [ { "id": 4, "code": "IN", "name": "India", "recordVersion": "6CB5C760-E145-4FFA-AC63-FAF5F36B6C80", "updatedBy": "Sini " }, { "id": 59, "code": ...