Question

I have a model Car which has_paper_trail. How can I find all cars which where changed or created by current_user? I could loop through all of them but that is a performance nightmare. Some where search is what I'm searching for but can't find.

Was it helpful?

Solution

There should be a whoddunnit column in the versions table which you can query in conjunction with item_type, but it's only useful if it is recorded properly.

A simple query to get IDs of the modified records:

PaperTrail::Version.where(whodunnit: current_user.id, item_type: 'Car').select('distinct item_id')

See also https://github.com/airblade/paper_trail#finding-out-who-was-responsible-for-a-change

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top