Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
Getting data from foreign key of other table - TypeOrm(Mysql)

I am using nestjs and typeorm (Mysql). I have these tables users, orders and invoices. Now invoices table has a foreign key linking to orders table and orders table links to user table.

Now when i am fetching invoices , i want to query user table , but i dont have foreign key for user table instead i have for order table and order table has foreign key for user table.

Is there any way to query user table when fetching invoice data ?

I tried the below code

const query = this.createQueryBuilder('invoice');

    query.innerJoinAndSelect('invoice.order', 'order');
    query.innerJoinAndSelect('order.user', 'user');

But it is giving this error

[Nest] 96607   - 11/09/2021, 11:08:49   [ExceptionsHandler] Relation with property path user in entity was not found. 
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It's more an advice than a solution.

TypeORM is not very intuitive and the documentation is not clear about it.

I reccomend you to change to a futuristic ORM, "PRISMA", the migration is very easy.

After installing it run this commands:

This command generates the schema automatically bassed on your database.

prisma introspect

This command applies the changes in your prisma schema.

prisma generate

After that youll have a pretty easy and accurate access to relationships.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!