-
Notifications
You must be signed in to change notification settings - Fork 898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to implement paper_trail on has_many associations #148
Comments
+1 |
+1 Any word on this? |
Not yet, but suggestions are welcome. I'm going to visit this soon when I started tackling the |
I was just thinking about this. How about a
I'm sure a join table would keep things cleaner, and I don't think you can extend this functionality properly without introducing join tables. This would be much cleaner:
Then, when calling
This would work for Thoughts? Or am I perhaps missing some subtle complexity? |
@damien-roche - Thanks for the suggestion, I believe that the concept of a |
@fullbridge-batkins - I'm still getting up to speed on this issue, so apologies in advance if these comments cover old ground. Building slightly on the comment above from @damien-roche (which according to your comment builds on a PR from @tderks) Is the problem simplified by creating a new version of the parent each time a child object (either In pseudo code: p = Person.create
# p.versions.count == 1
h = p.homes.create
# p.versions.count == 2
# h.versions.count == 1
h.update_attribute :name, 'test'
# p.versions.count == 3
# h.versions.count == 2 I realise this increases the number of versions considerably but it does ensure the |
@myitcv - It seems like this should probably work along these lines. Again, I haven't had a chance to take a proper crack at this but I'm planning on doing so soon. |
@fullbridge-batkins - great to hear. Is it worth pulling together a wiki page where people can capture requirements/edge cases? Would that be useful? |
Hey all, It's been some time since i worked on it, focused on finishing my study.
To summarize it is a complex feature, which brings me to an easy but less complete solution which could be usefull in alot of cases. In my previous patch i also introduced transaction support. For every model change it also stores the transaction id. With a new function called 'rollback' you can restore all the objects changed in the same transaction. This does not allow you to restore objects including relations to a specific time. However it does allow you to rollback child objects that are created/deleted when the parent is created/deleted very easily! I could probably wrap up this feature including unit tests in one evening! |
@tderks - If you have the time / bandwidth to take another crack at it, that would be awesome. I was going to go back and take a look at your work and try to merge it in later this week or early next week but I'm a bit concerned I'll be lost. I'd say that the feature doesn't have to be amazing off the bat, I just wanted to include some sort of functionality that provides at least a partial solution for this type of thing in the final |
Hey, I read a lot of threads about this issue and I'm a bit confused right now. I have models similar in principle to the
Should this work? Basically, when I come back to a previous version, only the associated models at the time should be returned, right? |
Theoretically thats what the code in pull request #90 would do, but it hasn't been merged in. I'm putting it off until |
Ok, thanks a lot for confirming this. I'll try to work with #90, see if it works for me, for now, and I'll upgrade to 3.1.0 when it's released! |
Any update for this issue? I really appreciate the update soon. Thanks. |
Just an idean : why not using the metadatas ? class Chapter < ActiveRecord::Base
belongs_to :book
has_paper_trail meta: {restor_books :books_count}
end And yet if you restore the chapter just go find the n books having this chapter id in there chapter_id column. |
@gdurelle its not a very scalable solution being an n+1 query |
I think I have this implemented. I'll try to get a PR together in a couple weeks. |
@NullVoxPopuli please let me know, if you will require some help. |
How much do we want to depend on active record? I also ran in to a snafu with soft deleted records, which has been addressed, but I know a couple of the soft delete gems allow customization of the column that tracks the deleted_at date, so, I don't know how to best handle that (generically) either. |
Hey all, there is an open PR in #345 which I think may be the solution we're looking for, at least the author (@lyfeyaj) claimed he had some success with it, I am trying to give it attention soon. Just been real busy with new stuff at work and what not recently, but I am making progress towards |
that looks kinda similar, but simpler than what I did. I wonder if all my specs will pass under that code |
@NullVoxPopuli at least you have specs, it's a half of work. ;) |
Closed in favor of #439, thanks to everyone who contributed to the dialog here. |
Actually 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:
The above example represent the informations of ABC inc
How can I implement the following operation so It will reset the company and the company's ceos names to the last version?
The text was updated successfully, but these errors were encountered: