lundi 23 novembre 2015

When softDeletes() is use with the parent, what is the best way to handle all of its child

I have a table for publications, which has a relationship of one-to-many with the table reviews, each publication has many reviews.

I'm using AngularJS for the frontend and Laravel for the backend and MySQL for the database.

Let's say I would softDeletes() one of the publication, should I also need to use softDeletes() to all of its reviews? When softDeletes() is used with the parent, what is the best way to handle all of its child

Currently this is the solutions that I can think of base on my research but I still have doubts to what is the best way regarding of performance :

1. Only update the deleted_at column in publications table and leave 
   the reviews table as it is.

2. Create a MySQL trigger to update the deleted_at column in reviews 
   table when user softDeletes() the publication.

3. Update deleted_at column in table reviews inside laravel controller, 
   which will use foreach. But I think this has a performance issue assuming 
   that the publication have hundreds or thousands of reviews.

4. Create a different table for reviews which parent is temporarily inactive. 
   Separating reviews that are active and inactive, I think this will help in 
   query performance. I'm not sure.

Sorry if some of my grammar is wrong but if you understand my question I would be happy to hear your thoughts. Thank you.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire