PGBI / cakephp3-soft-delete

83 stars 60 forks source link

Soft deleted records should be fetched for belongsTo association queries. #20

Closed mohsinrasool closed 8 years ago

mohsinrasool commented 8 years ago

Hi,

I have been using your script for couple of my projects. Thanks for sharing it.

I have invoices that has a belongs to relation with clients model. When a client is soft deleted, all of its invoices shows empty clients array. Does this make sense that even if records is soft deleted, it should show up in belongs to relations? If so, how can that be implemented?

Thanks

miguelfrmn commented 8 years ago

+1

miguelfrmn commented 8 years ago

@mohsinrasool You should be able to accomplish it like this:

'contain' => [ 'Users' => function ($q) { return $q->find('all', ['withDeleted']); } ]