I use paper_trail in rails to track my models versions. But the documentation on the github repo indicates that the gem doesn't support has_many
, belongs_to
associations.
Let's say I've an app that records the ceos names of some comapnies:
class Company < ActiveRecord::Base has_many :ceos has_paper_trail end class Ceo < ActiveRecord::Base belongs_to :companies has_paper_trail end
The above example represent the information of ABC Inc.
company.name => "ABC" company.ceo.past => "John Henry" company.ceo.present => "Amy Warren"
How can I implement the following operation so it will reset the company and the company's ceos names to the last version?
You could attempt to re-model the association to remove the has_many because in the case of CEOs, a company may have_many CEOs through its life, but it only has_one CEO for a certain period.
The implementation of this might be a has_one to a join table made up of the ID of both CEO and Company, and the time periods it was valid for.
A beneficial side effect is it would become trivial to have a person be CEO of a company 2 times with another CEO in between and have easy traversal of that in the domain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With