Reputation: 1092
I am trying to update my productDetails
table and productMaster
table.
Here is my relation:
ProductMaster.ts:
@OneToOne(type => ProductDetails, productDetails => productDetails.productMaster,{
cascade: ["insert", "update"]
})
productDetails: ProductDetails;
ProductDetails.ts:
@OneToOne(type => ProductMaster, productMaster => productMaster.productDetails,{
cascade: ["insert", "update"]
})
@JoinColumn({name: 'prd_id', referencedColumnName: 'prd_id'})
productMaster: ProductMaster;
Now I have to update my productMaster
and productDetails
using TypeORM relations.
Here is what I tried:
productMasterRepository
.createQueryBuilder()
.update()
.set({
prd_name : 'my Product Name'
productDetails : {
prd_brand : 'My Product Brand Name'
}
})
.where("prd_id = :prd_id", {prd_id: 1})
.execute();
But it doesn't update.
Upvotes: 4
Views: 1826
Reputation: 667
Okay, so the problem here is you want to join the tables and update them both at the same time it will use joins, but it is not possible to create complex queries like this.
Typeorm only supports joins
on the select expression
refer to this Refer This
It is only possible using raw queries
Upvotes: 1