Laraue.EfCoreTriggers icon indicating copy to clipboard operation
Laraue.EfCoreTriggers copied to clipboard

Condition check if it is the last reference in after delete

Open JohanArleth opened this issue 2 years ago • 0 comments

Is it possible to configure a trigger like this one with this library?

What i'm trying to achieve is to delete one side of a many to many relationship table if this is the last row pointing to it

Tables: -Persons -PersonProducts -Products

i want the product to be deleted when the last PersonProduct referencing it is deleted

builder
                .AfterDelete(trigger => trigger
                    .Action(action => action
                        .Condition(pp => pp.Product!.PersonProducts.Count() == 1)
                        .Delete<Product>((personProduct, product) => personProduct.ProductId == product.Id)
                    )
                );

JohanArleth avatar May 20 '22 15:05 JohanArleth