11

I can add the SoftDelete behaviour on a ManyToMany reference table, this will add a deleted_at column. Unfortunately setting the column to a not NULL value, will not filter out the relations. This is what I had hoped.

Does anybody know a workaround without actually referencing the reference table?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Michiel Thalen
  • 300
  • 2
  • 12
  • I don't know about doctrine, but can you run a select statement similar to SQL: SELECT * FROM myModel WHERE deleted_at IS NULL ? – Chase Roberts Apr 30 '15 at 23:56
  • I'm not using doctrine, but I faced a related problem in Laravel. Pivot tables usually should have a unique constraint on (pk1,pk2) with pki being the primary key of table i. Soft deleting here is not very straight forward. What if you soft delete a relation, then want to insert the same? In this case you must undelete the soft deleted relation instead of inserting a new one. But then if you store other information in your pivot, you will loose soft deleted data. Is not it better to have another table (with no unique constraint) to store deleted relations? – Hamid Alaei May 01 '15 at 10:05
  • What kind of SoftDelete are you using? Did you try implementing ManyToMany yourself through ManyToOne->HelperClass<-OneToMany, where you can tweak the HelperClass? – Jan Mares Dec 01 '16 at 13:15
  • Instead of introducing `deleted_at` in your junction table add this in your referenced entities and filter your records while fetching your entities – M Khalid Junaid Sep 16 '17 at 16:46

1 Answers1

0

You may add a listener in the template for the soft-delete. Then you can hook into the preDqlSelect method and add the needed dql part.

Tarik Weiss
  • 336
  • 2
  • 15