Loopback 4 delete relation

1.2k Views Asked by At

I am staring with lp4, i I have following two models

Product

ProductTranslations

the Product hasMany relation with the ProductTranslations model How can i delete product, ProductTranslations will be deleted corresponding to product

2

There are 2 best solutions below

0
On BEST ANSWER

What you're looking for is cascade delete. LoopBack 4 does not support this out-of-the-box (see issue #3526).

As a workaround, you may override the .delete() Repository function to start a Transaction and emulate a cascade delete with full ACID compliance.

1
On

@del('/users/{id}')
  @response(204, {
    description: 'User DELETE success',
  })
  async deleteById(@param.path.string('id') id: string): Promise<void> {
    await this.userRepository.deleteById(id);
  }