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

How can I arrange selected options at the top in MUI autocomplete?

I am currently working with mui's useAutocomplete hook https://mui.com/material-ui/react-autocomplete/#useautocomplete Is there a way to programmatically sort options and place the selected option at the top using JavaScript sorting, without resorti ...

unable to locate the nested routes in the folder for remix

Hey there, I've been using the remix to create a basic page and I'm trying to organize the routes using folders. Here is my project directory: - app/ - root.tsx - examples/ - route.tsx - child1/ - account.tsx In the examples di ...

Efficiently process and handle the responses from Promise.all for every API call, then save the retrieved data

Currently, I am passing three API calls to Promise.all. Each API call requires a separate error handler and data storage in its own corresponding object. If I pass test4 to Promise.all, how can I automatically generate its own error and store the data in ...

The Angular tag <mat-expansion-panel-header> fails to load

Every time I incorporate the mat-expansion-panel-header tag in my HTML, an error pops up in the console. Referencing the basic expansion panel example from here. ERROR TypeError: Cannot read property 'pipe' of undefined at new MatExpansionPanel ...

Master your code with Rxjs optimization

Looking at a block of code: if (this.organization) { this.orgService.updateOrganization(this.createOrganizationForm.value).subscribe(() => { this.alertify.success(`Organization ${this.organization.name} was updated`); this.dialogRef.close(true ...

Why does the method of type assigning vary between actual and generic types?

There are no errors in the code shown below: type C = {b: string}; class Class { data: C; constructor(data: C) { this.data = data; } test() { const hack: C & {a?: any} = this.data; //no error } } However, when a g ...

The POST requests on Next JS Mock API endpoints include parameters passed in the req.body

I am currently running Next JS API tests using jest with a custom testClient. The code for the testClient is as follows: import { createServer } from 'http'; import type { NextApiHandler } from 'next'; import type { __ApiPreviewProps } ...

Exploring the process of dynamically updating a form based on user-selected options

I need assistance with loading an array of saved templates to be used as options in an ion-select. When an option is chosen, the form should automatically update based on the selected template. Below is the structure of my templates: export interface ...

Is it possible to pass a different variable during the mouse down event when using Konva for 2D drawing?

I am trying to pass an additional value in a mouse event because my handleMouseDown function is located in another file. stage.on('mousedown', handleMouseDown(evt, stage)) Unfortunately, I encountered an error: - Argument of type 'void&apos ...

What is the best way to set the generics attribute of an object during initialization?

Below is the code that I have: class Eventful<T extends string> { // ↓ How can I initialize this attribute without TypeScript error? private eventMap: Record<T, (args?: any) => void> = ? } Alternatively, class Eventful<T extends st ...

Experiencing difficulty creating query files for the apollo-graphql client

I'm currently attempting to learn from the Apollo GraphQL tutorial but I've hit a roadblock while trying to set up the Apollo Client. Upon executing npm run codegen, which resolves to apollo client:codegen --target typescript --watch, I encounter ...

What could be causing React to generate an error when attempting to utilize my custom hook to retrieve data from Firebase using context?

Currently, I am restructuring my code to improve organization by moving data fetching to custom hooks instead of within the component file. However, I am encountering issues with the hook not functioning properly when used in conjunction with my context. ...

Tips for choosing and filtering the preferred object in ES6

Consider this array structure: const testData = [ { group: "Team1", info: [ { key: 123, person: "Alice", type: "Football" }, { key: 456, person: "Bob", type: " ...

Tips for deleting a specific choice with Angular

Having recently started working with Angular2 / TS / ES6, I am struggling to find a solution to my issue. I have a select element with dynamically rendered options using ngFor from an array. These options are meant for selecting attributes for a product. ...

Why is it not possible to convert from any[] to MyType[] in TypeScript?

Within TypeScript, the any type allows for casting to and from any arbitrary type. For example, you can cast from a variable of type any to a variable of type MyArbitraryType like so: var myThing: MyArbitraryType; var anyThing: any; myThing = anyThing; / ...

Error: global not declared in the context of web3

I've been attempting to integrate Web3 into my Ionic v4 project for some time now. However, I keep encountering errors when I try to serve the project. Specifically, I receive an error message stating that Reference Error: global is not defined. Cre ...

What is the best method for translating object key names into clearer and easier to understand labels?

My backend server is sending back data in this format: { firstName: "Joe", lastName: "Smith", phoneNum: "212-222-2222" } I'm looking to display this information in the frontend (using Angular 2+) with *ngFor, but I want to customize the key ...

Having a problem where the Next.js project is functioning in development mode, but encountering a "module not found" error

After following multiple tutorials to integrate Typescript into my existing app, I finally got it running smoothly in dev mode using cross-env NODE_ENV=development ts-node-script ./server/index.js However, when I execute next build, it completes successfu ...

Create and export a global function in your webpack configuration file (webpack.config.js) that can be accessed and utilized

Looking to dive into webpack for the first time. I am interested in exporting a global function, akin to how variables are exported using webpack.EnvironmentPlugin, in order to utilize it in typescript. Experimented with the code snippet below just to und ...

The combination of React, Typescript, and MaterialUI Paper results in a stunning design with a sleek and

Whenever I include <Paper elevation={0} /> within my react component, I encounter the following issue: Cannot read properties of undefined (reading 'background') TypeError: Cannot read properties of undefined (reading 'background&apos ...