What steps should I take to establish a one-to-one relationship with legacy tables?

As I work on developing a web application (angular, nestjs, typeorm), I am faced with the challenge of linking two legacy user tables together within our existing system. Despite my efforts, I continue to encounter an error message related to column references. Specifically, I keep receiving the error "TypeORMError: Referenced column userid was not found in entity Foruser."

The table in question is the authentication table, which previously stored sensitive information such as user passwords.

@Index("pk_foruser", ["id"], { unique: true })
@Entity("foruser", { schema: "dbo" })
export class Foruser {
  @PrimaryColumn("varchar", { name: "id", length: 28 })
  id: string;

  @OneToOne(() => Adbuinfo)
  Profile: Relation<Adbuinfo>;
}

On the other hand, we have the User profile table containing permissions and application details.


@Index("pk_adbuinfo", ["userid"], { unique: true })
@Entity("adbuinfo", { schema: "dbo" })
export class Adbuinfo {
  @PrimaryColumn("varchar", {  name: "userid", length: 32 })
  userid: string;

  @OneToOne(() => Foruser, (Foruser) => Foruser.Profile, { cascade: true})
  @JoinColumn({name: 'id', referencedColumnName: 'id'})
  User: Relation<Foruser>;
}

Unfortunately, altering the primary key column names is not a feasible solution due to the usage of these tables in other applications.

Edit: Here is the complete stack trace of the error.

TypeORMError: Referenced column userid was not found in entity Foruser
    at C:\Development\Web Adtakr-1\adtakr-service\src\metadata-builder\RelationJoinColumnBuilder.ts:151:27
    at Array.map (<anonymous>)
    at RelationJoinColumnBuilder.collectReferencedColumns (C:\Development\Web Adtakr-1\adtakr-service\src\metadata-builder\RelationJoinColumnBuilder.ts:143:32)
    at RelationJoinColumnBuilder.build (C:\Development\Web Adtakr-1\adtakr-service\src\metadata-builder\RelationJoinColumnBuilder.ts:62:40)
    at C:\Development\Web Adtakr-1\adtakr-service\src\metadata-builder\EntityMetadataBuilder.ts:180:60
    at Array.forEach (<anonymous>)
    at C:\Development\Web Adtakr-1\adtakr-service\src\metadata-builder\EntityMetadataBuilder.ts:173:22
    at Array.forEach (<anonymous>)
    at EntityMetadataBuilder.build (C:\Development\Web Adtakr-1\adtakr-service\src\metadata-builder\EntityMetadataBuilder.ts:166:14)
    at ConnectionMetadataBuilder.buildEntityMetadatas (C:\Development\Web Adtakr-1\adtakr-service\src\connection\ConnectionMetadataBuilder.ts:106:11)

Any attempts to modify the names or references to the 'userid' column result in the error message shifting to the inability to locate 'userid' within Foruser.

Answer №1

After closely examining my situation, I realized where the problem was originating from. Instead of broadening my perspective and considering all entities involved, I mistakenly fixated on just two tables. It turns out, the issue actually stemmed from a third entity that had a one to many relationship with Foruser.

This serves as a reminder for those who may come across this question in the future (assuming it is not removed by a moderator). Always keep in mind that the root cause of a problem may not always be where you initially suspect it to be.

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

Steer clear of utilizing the "any" type in your Express.js application built with

I have a node/express/typescript method that looks like this: // eslint-disable-next-line export const errorConverter = (err: any, req: any, res: any, next: any) => { let error = err if (!(error instanceof ApiError)) { const statusCode = e ...

Using an AWS API Gateway, an HTTP client sends a request to access resources

I have a frontend application built with Angular and TypeScript where I need to make an HTTP request to an AWS API Gateway. The challenge is converting the existing JavaScript code into TypeScript and successfully sending the HTTP request. The AWS API gat ...

Verifying completed fields before submitting

I'm in the process of designing a web form for users to complete. I want all fields to be filled out before they can click on the submit button. The submit button will remain disabled until the required fields are completed. However, even after settin ...

What is the best way to utilize my data with Charts.js for my specific situation?

I am utilizing Charts.js in my Angular project (not AngularJS) and I am trying to create a graphic representation with data from my database that shows the distribution between men and women. However, I am struggling to figure out how to loop through the d ...

Dependency mismatch in main package.json and sub package.json

Imagine you have a project structure in Typescript set up as follows: root/ api/ package.json web/ package.json ... package.json In the main package.json file located in the root directory, Typescript is installed as a dependency to make ...

Is there a way to incorporate new members into a pre-existing type in TypeScript?

While examining the definition file for the commander project, one can observe the following interface being utilized: interface IExportedCommand extends ICommand { Command: commander.ICommandStatic; Option: commander.IOptionStatic; [key: stri ...

When working with Angular/Typescript, the error message "compilation of 'export const' is not possible

Embarking on creating my very own Angular library, I took the first step by adding a service without any issues. The challenge arose when I decided to move a constant to a file named tokens.ts for the service to reference. Following this change, the build ...

Testing Angular components using mock HTML Document functionality is an important step in

Looking for help on testing a method in my component.ts. Here's the method: print(i) { (document.getElementById("iframe0) as any).contentWindow.print(); } I'm unsure how to mock an HTML document with an iframe in order to test this meth ...

Angular Typescript error: Trying to assign a value to 'someProperty' property of an undefined object

Within my Article class, I have a property called Image which is structured like this: export class Article { public image:Image; public images: Image[]; } If I decide to comment out this.article.image = new Image(); in the following way: constru ...

When utilizing AngularFire with Firebase Firestore Database, users may encounter instances where data duplication occurs on

Currently facing a challenge in my Angular 13.1 Project utilizing @angular/fire 7.4.1 for database management The issue arises consistently across various screens where data from Firestore Database is displayed, particularly on List screens. The lists are ...

Converting a file buffer to upload to Google Cloud Storage

I have been facing an issue while attempting to upload a file to Google Cloud using a buffer and the save function. The problem I am encountering is that even though the files are uploaded to Google Cloud, they are not in the correct format. When I try to ...

Can ng-content be utilized within the app-root component?

I have successfully developed an Angular application, and now I am looking to integrate it with a content management system that generates static pages. In order to achieve this, I need to utilize content projection from the main index.html file. The desi ...

Directive for Angular 2: Expand Further

Looking to create a custom readmore directive in Angular2 that will collapse and expand long blocks of text based on a specified max height, rather than character count. The directive will include "Read more" and "Close" links. <div read-more [maxHeigh ...

What are the potential drawbacks of using this alternative method instead of `useCallback` in React to prevent unnecessary re-renders of children components?

While exploring some code, I stumbled upon an alternative method to prevent function recreation during renders compared to the official useCallback hook. This method seems to offer certain benefits over useCallback, but I am interested to know if there are ...

Setting up types for variables in Angular 2 componentsHere is an

I have a model that consists of multiple properties, and I aim to set all these properties with a default value of either empty or null. Here is an example of my Model: export class MyModel { name: string; jerseyNumber: number; etc... } In m ...

The path mappings specified in the tsconfig.json file are not resolving correctly during the

Everything runs smoothly with my imports during coding, but after building the project using tsc, the imported files are not resolving to valid paths. This is how my tsconfig.json looks: { "compilerOptions": { "target": "ES2 ...

Retrieve the status callback function from the service

Can anybody show me how to set up a call-back function between a component and a service? I apologize for my lack of experience with Angular and TypeScript. getDiscount(){ let getDisc = []; getDisc.push({ price: Number(this.commonService.getP ...

Retrieve an array of specific column values from an array of objects using Typescript

How can I extract an array from an array of objects? Data var result1 = [ {id:1, name:'Sandra', type:'user', username:'sandra'}, {id:2, name:'John', type:'admin', username:'johnny2'}, ...

Categorizing the types of dynamically retrieved object values

I've developed a unique class with two properties that store arrays of tuples containing numbers. Additionally, I've implemented a method called "getIndex" which dynamically accesses these properties and checks for duplicate number values within ...

Deriving variable function parameters as object or tuple type in TypeScript

Searching for a similar type structure: type ArgsType<F extends Function> = ... which translates to ArgsType<(n: number, s: string)=>void> will result in [number, string] or {n: number, s: string} Following one of the provided solu ...