How to prevent duplicate entities in many-to-many table with Angular

How can I prevent duplication of records with the same combinations of entities, here : id_product and id_customer. When I click "save relation" a relation (many-to-many) between product and customer is created and this relation has its own id, id_product and id_customer. Is there any solution to block creation of relation between product and customer if such combination already exists in MySQL database ?

public saveRelation = (relationFormValue) => { const newRelation = {   id_product: relationFormValue.id_product ,   id_customer: relationFormValue.id_customer };  const dialogRef = this.dialog.open(ConfirmDialogComponent, {   maxWidth: "400px",   data: new ConfirmDialogModel("Please confirm",'Are you sure to save this relation ?') });  dialogRef.afterClosed().subscribe(dialogResult => {   if (dialogResult==true) {     this.relationService.create(newRelation)       .subscribe(         response => {           this.dialogRef.close(true);                       },         error => {           this.errorService.handleError(error);         });   } }); 

}

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.