The field list contains an unidentified column named 'Test.computerIDComputerID'

I am currently navigating through the syntax of typeORM and have been stuck troubleshooting an issue for quite some time. It appears that whenever I utilize the find() function in typeORM, a query is generated with a duplicated column from a relation. Here is a snippet of the code I've been working on:

if(!typeORM.isInitialized)
    await typeORM.initialize()

const test2 = await typeORM.getRepository(Test)
const result  = await test2.find({where: {testID: 98}, relations: {computerID:true}})
console.log(result)

When running this code, I encounter the following error:

  code: 'ER_BAD_FIELD_ERROR',
  errno: 1054,
  sqlMessage: "Unknown column 'Test.computerIDComputerID' in 'field list'",
  sqlState: '42S22',
  index: 0,
  sql: 'SELECT `Test`.`testID` AS `Test_testID`, `Test`.`name` AS `Test_name`, `Test`.`testParameters` AS `Test_testParameters`, `Test`.`saveOutput` AS `Test_saveOutput`, `Test`.`deploy` AS `Test_deploy`, `Test`.`computerIDComputerID` AS `Test_computerIDComputerID`, `Test`.`suiteIDSuiteID` AS `Test_suiteIDSuiteID`, `Test__Test_computerID`.`computerID` AS `Test__Test_computerID_computerID`, `Test__Test_computerID`.`ip` AS `Test__Test_computerID_ip`, `Test__Test_computerID`.`name` AS `Test__Test_computerID_name`, `Test__Test_computerID`.`deployPath` AS `Test__Test_computerID_deployPath`, `Test__Test_computerID`.`cpu` AS `Test__Test_computerID_cpu`, `Test__Test_computerID`.`cores` AS `Test__Test_computerID_cores`, `Test__Test_computerID`.`architecture` AS `Test__Test_computerID_architecture`, `Test__Test_computerID`.`ram` AS `Test__Test_computerID_ram`, `Test__Test_computerID`.`hdd` AS `Test__Test_computerID_hdd`, `Test__Test_computerID`.`speed` AS `Test__Test_computerID_speed`, `Test__Test_computerID`.`os` AS `Test__Test_computerID_os`, `Test__Test_computerID`.`user` AS `Test__Test_computerID_user`, `Test__Test_computerID`.`password` AS `Test__Test_computerID_password` FROM `Test` `Test` LEFT JOIN `Computer` `Test__Test_computerID` ON `Test__Test_computerID`.`computerID`=`Test`.`computerIDComputerID` WHERE (`Test`.`testID` = 98)'

This leads me to my two table entities:

@Entity({name:"Test",synchronize: false})
export class Test{
    @PrimaryGeneratedColumn({ type: "int" })
    testID!: number;         
    @Column({ type: "varchar", length: 50, unique: true })
    name!: string;    

    @ManyToOne(() => Computer, computer => computer.tests)
    @JoinTable({ name: 'computerID'})
    computerID!: Computer;

    @ManyToOne(() => Suite, suite => suite.Test)
    @JoinTable({name: "suiteID"})
    suiteID!: Suite;

    @Column({ type: "varchar", length: 300 })
    testParameters!: string;
    @Column({ type: "tinyint" })
    saveOutput!: number;        
    @Column({ type: "varchar", length: 45 })
    deploy!: string;

    @OneToMany(() => Execution, execution => execution.testID,{cascade: ['insert','update']})
    Execution!: Execution[]

    @OneToMany(() => Scheduler, scheduler => scheduler.testID,{cascade: ['insert','update']})
    Scheduler!: Scheduler[]

}

@Entity({name:"Computer",synchronize: false})
export class Computer {
    @PrimaryGeneratedColumn({ type: "int" })
    computerID!: number;
    @Column({ type: "varchar" })
    ip!: string;
    @Column({ type: "varchar",unique: true })
    name!: string;     
    @Column({ type: "varchar"})
    deployPath!: string;     
    @Column({ type: "varchar"})
    cpu!: string;
    @Column({ type: "varchar"})
    cores!: string;
    @Column({ type: "varchar"})
    architecture!: string;
    @Column({ type: "varchar",unique: true })
    ram!: string;     
    @Column({ type: "varchar"})
    hdd!: string;
    @Column({ type: "varchar"})
    speed!: string;
    @Column({ type: "varchar"})
    os!: string;
    @Column({ type: "varchar"})
    user!: string;     
    @Column({ type: "varchar"})
    password!: string;

    @OneToMany(() => Execution, execution => execution.computerID)
    Execution!: Execution[]

    @OneToMany(() => Test, test => test.testID,{cascade: ['insert','update']})
    tests!: Test[]

}

My suspicion lies within the relational structure, as I have successfully implemented similar relationships in the past without encountering such errors.

Answer №1

After some careful examination, I uncovered the minor error that was causing my confusion. Rather than utilizing JoinTable for the ManyToOne/OneToMany relationships, the correct approach is to use JoinColumn.

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

The function parameter in Angular's ngModelChange behaves differently than $event

How can I pass a different parameter to the $event in the function? <div class='col-sm'> <label class="col-3 col-form-label">Origen</label> <div class="col-4"> <select ...

Sending a POST request in Angular5 using the HTTP module

Angular 5 Attempting to create a function that will generate a resource on my API using Angular has proven to be a challenge. The "employee.service.ts" file contains a method named "saveEmployee" which is triggered by a function called "addEmployee" locate ...

Establishing the correct data type to be returned from a fetch function in order to align with a specific custom type

My app has two interfaces defined: export interface Job { job_title: string, employer: string, responsibilities: string[] achievements: string[], start_date: string, end_date: string } export interface CreatedJob extends Job { ...

Issue with Angular 10 Web Worker: Unable to locate the main TypeScript configuration file 'tsconfig.base.json'

Every time I attempt to run: ng g web-worker canvas I consistently encounter the error message: Cannot find base TypeScript configuration file 'tsconfig.base.json'. After thorough examination of my files, it appears that I am indeed missing a ...

Is there a way to update the text of a button when it is clicked?

Is there a way to dynamically change the text of a button when it is clicked and revert back to its original text when clicked again? I have attempted something along these lines, but I am unsure how to target the text since there isn't a property si ...

What could be the reason for the component not receiving data from the service?

After attempting to send data from one component to another using a service, I followed the guidance provided in this answer. Unfortunately, the data is not being received by the receiver component. I also explored the solution suggested in this question. ...

Combining properties from one array with another in typescript: A step-by-step guide

My goal is to iterate through an array and add specific properties to another array. Here is the initial array: const data = [ { "id":"001", "name":"John Doe", "city":"New York&quo ...

Angular 6 - Accessing row information by clicking a toggle button

To retrieve the row details upon clicking a specific toggle button, I need to access the "row" data. Below is the snippet of my HTML code: <div class="container"> <div> <h3>Manage Announcements</h3> </div> <div& ...

Queries with MongoDB RegEx fail to return any matches if the search string contains parentheses

When trying to implement case-insensitivity using regex, it seems to work well for plain strings. However, if special characters like parenthesis are involved in the search query for the name, the database returns no results. For example, a search for "Pu ...

Removing empty options from a select dropdown in Angular 9

In the process of working with Angular 9, I am currently in the process of constructing a dropdown menu that contains various options. However, I have encountered an issue where there is a blank option displayed when the page initially loads. How can I eli ...

Calculate age in years and months using a PHP timestamp

Currently, I am executing the following SQL script: SELECT TIMESTAMPDIFF(YEAR,CONCAT(dob_year, '-', dob_month, '-', dob_day),CURDATE()) as age FROM members This query is used to calculate the ages of users based on a timestam ...

Content obscuring dropdown menu

I am currently working on a screen design that resembles the following: return ( <SafeAreaView> <View style={styles.container}> <View style={styles.topContainer}> <View style={styles.searchFieldContainer}> ...

Should Angular libraries be developed using Typescript or transpiled into JavaScript?

Currently, I am in the process of developing a library that will be available as an Angular module through npm. The library itself has been written using typescript. Everything was functioning perfectly up until Angular version 5.0.0, but after this update ...

A guide on implementing code sharing in NestJS using Yarn Workspaces

I'm currently working on a proof of concept for a basic monorepo application. To structure my packages, I've decided to use Yarn Workspaces instead of Lerna as it seems more suitable for my needs. One of the packages in my setup is shared, which ...

Switching from a TypeOrm custom repository to Injectable NestJs providers can be a smooth transition with the

After updating TypeORM to version 0.3.12 and @nestjs/typeorm to version 9.0.1, I followed the recommended approach outlined here. I adjusted all my custom repositories accordingly, but simply moving dependencies into the providers metadata of the createTe ...

Dealing with throwing Exceptions in jest: A guide for developers

I have developed a method that throws an exception when the provided password does not match a regex pattern. I attempted to handle this in Jest. it('Should prevent insertion of a new user if the password doesn't match the regex', async () ...

Using Typescript to set the image source from a pipe

I've been working on creating a custom pipe similar to the code below: @Pipe({ name: 'imagePipe' }) @Injectable() export class ImagePipe { constructor(public someService: SomeService, public storage: Storage) { } transform(value: ...

Verifying the presence of a value within an SQL table

I am currently working on developing a bot that requires me to save the commandname and commandreply in a database. Right now, I am using mySQL Workbench for this task. My goal is to verify if the commandname provided by the user already exists in the tab ...

Steps for initiating an Angular 4 project

While most developers have moved on to Angular 5, I was tasked with creating a project using Angular 4. After conducting research for several days, I discovered that downgrading the Angular CLI would allow me to accomplish this. By following this approach, ...

The canActivate: [AuthGuard] feature on the external router is not functioning as expected

I'm encountering an issue with my routing. I attempted to use the following code: const routes: Routes = [ { path: 'home', component: HomeComponent, canActivate: [AuthGuard], children: [ { path: 'events', component: Ev ...