I'm using paper trail in my app partially to display an audit log of changes and have noticed that it won't track destroy events when items in join tables are soft deleted (it works fine for other tables). I have a model that looks something like this:
module Book
class BookGenre < ApplicationRecord
acts_as_paranoid
has_paper_trail
belongs_to :book, inverse_of: :book_genres
belongs_to :genre
validates :book, presence: true
validates :genre, presence: true
end
end
# == Schema Information
#
# Table name: book_genres
#
# id :bigint not null, primary key
# deleted_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# genre_id :integer not null
# book_id :integer not null
#
Changes to this table are made through the update method in the "book" controller. When a "genre" is removed from a book paper trail doesn't write anything to the versions
table, so these events are not properly tracked.
For a model that looks something like this it tracks both create and destroy events as expected when updating though the same "book" controller method:
module Book
class Cover < ApplicationRecord
acts_as_paranoid
has_paper_trail
belongs_to :book
validates :book, presence: true
validates :cover_link, presence: true
end
end
# == Schema Information
#
# Table name: book_genres
#
# id :bigint not null, primary key
# deleted_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# book_id :integer not null
# cover_link :string not null
#
My hunch is that this has something to with the fact that "book_genres" is a join table. Any ideas on how to get this working the way I want?
I've tried:
- Explicitly telling paper trail to track destroy operations instead of relying on defaults with
has_paper_trail :on => [:update, :create, :destroy]
- Installing and setting up the paper_trail-association_tracking gem
- Upgrading paper trail to the latest version
- Read through the paper trail docs and not found what I'm looking for (although maybe I missed it)