logidze icon indicating copy to clipboard operation
logidze copied to clipboard

reload_log_data doesn't work when used with acts_as_paranoid and deleted records

Open matgaw opened this issue 2 years ago • 2 comments

Tell us about your environment

**Ruby Version:3.0.5

**Rails Version:7.0.4

**PostgreSQL Version:13.9

**Logidze Version:1.2.3

What did you do?

Using logidze and acts_as_paranoid in one project. When record is marked as deleted with acts_as_paranoid, and I load it like so:

obj = SomeObject.with_deleted.find(some_id)

and then execute:

obj.reload_log_data

What did you expect to happen?

log_data gets loaded

What actually happened?

The query is affected by acts_as_paranoid and adds WHERE "some_objects"."deleted_at" IS NULL - resulting in log_data being null.

Not sure how to work-around it, or which gem should actually fix it.

matgaw avatar Apr 13 '23 18:04 matgaw

Actually I think this should be reported to acts_as_paranoid gem

matgaw avatar Apr 13 '23 19:04 matgaw

I think, you posted issue in the right place.

We do not take scopes into account when reloading the log data: https://github.com/palkan/logidze/blob/fc891d83acbaf1179a98a5963994663f0a142eb8/lib/logidze/model.rb#L219

Adding .unscoped here makes senses. Or, probably, add an option to reload without taking default scopes into account: record.reload_log_date(unscoped: true)

palkan avatar Apr 13 '23 19:04 palkan