state-machines / state_machines-audit_trail

Log transitions on a state_machines gem to support auditing and business process analytics.
https://github.com/state-machines/state_machines-audit_trail
MIT License
75 stars 24 forks source link

Destroy transitions when resource id destroy #36

Open btrd opened 5 years ago

btrd commented 5 years ago

Fix this issue https://github.com/state-machines/state_machines-audit_trail/issues/14

seuros commented 5 years ago

@btrd , Thank you for your PR. I have some remarks about this change. :destroy will load every single instance of the change and destroy them one by one. If a record has thousands of changes , that could be a very expensive and slow process. :delete_all will delete all the records with 1 SQL query.

The best approach i can think of now, is to delegate this to the database by have a constraint : on_delete: :cascade on the foreign key.

I still think we can add this feature if we can make it configurable.

seuros commented 5 years ago

The foreign key approach will work only in Relational databases. MongoDB will still need this IFAIK.