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.
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.