The information you need is ultimately stored in the corresponding versions and version_associations tables.
However, paper_trail does not provide methods for accessing information the way you want. But you can write your own method yourself to get a list of version associations of an object.
Let's say you have the following models:
class Article < ApplicationRecord has_many :comments has_paper_trail end class Comment < ApplicationRecord belongs_to :article has_paper_trail end
You can find all versions of the comment object of the article article as follows:
PaperTrail::Version.where(item_type: 'Comment') .joins(:version_associations) .where(version_associations: { foreign_key_name: 'article_id', foreign_key_id: article.id }) .order('versions.created_at desc')
You can defuse the stone or define this method as an instance method of the Article class so that you can easily call it, for example article.comment_versions
Please note: the above information is not available in article.versions.first.changeset , because if you change the comment, but not the article, the article is not a version, but only a comment.
But the above method allows you to access the history of changes in associations.
source share