-
Notifications
You must be signed in to change notification settings - Fork 899
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
supporting has_many reification based on @lyfeyaj and @NullVoxPopuli 's works #439
Conversation
add has many associations functionality
…merge-with-lyfeyaj Conflicts: lib/paper_trail.rb lib/paper_trail/has_paper_trail.rb lib/paper_trail/version_concern.rb
…rsive reification of has_many; add tests
OK, I am done. :( The rest of the CI errors are due to Timecop's lack of support for Ruby 1.8.x and I can't find an easy replacement. |
maybe you could wrap some of this functionality in ruby version > 1.9? |
@bli there is also this https://github.com/bebanjo/delorean, which has similar functionality |
Thanks @NullVoxPopuli . It looks like the good old DeLorean is working well in the good old 1.8.7. I have to use the more updated Timecop in 1.9.2 and above though as it does a better cleanup when 'return', otherwise a few tests would have been broken. |
Wow this looks very promising and like a ton of effort has gone into this. Looking forward to reviewing this. I'm at a conference this week but will make time to comb through this soon. |
Is there a test showing that the has_manies are only tracked if there are changes? |
@NullVoxPopuli would you show a specific scenario for such a test? Currently there are tests to show that has_manies are tracked if they are changed. Btw, current the transaction id is derived from the version id and the version-association class is hard-coded to PaperTrail::VersionAssociation. This would become a problem for people using multiple version tables. I was thinking maybe we can add an option (e.g. :association_class_name) to customize the version-association class name, like the existing :class_name option. What do you guys think? Also, currently the version-association records are created as long as paper_trail is turned on and there are belongs_to associations. This might not be necessary or desired for some models from performance's perspective. What do you guys think about making it optional to capture these version-association records? Also, if we make the option to be false by default, we can reduce the impact to existing paper_trail users. |
… merge-with-lyfeyaj Conflicts: lib/paper_trail/has_paper_trail.rb
… merge-with-lyfeyaj Conflicts: lib/paper_trail/has_paper_trail.rb
@bli - Awesome work! And thanks for the quick feedback loop, apologies for being so slow on my end, been super busy at work lately. I think there are only a few loose ends to tie up before we can merge this. The install generator should have an option as to whether the association pieces are added (similar to what we do with the object_changes), and the README needs an update to talk about the functionality. I'm happy to try to do either but I figured I would give you an opportunity to take a crack at updating the README since you probably know the ins and outs of the feature(s) much better than I at this point, as well as any potential pitfalls. Are you up to that? |
I am happy to try updating the README. should be able to find some time either today or tomorrow. |
@bli - Do you think you'll still have time to take a crack at the README or do you want me to try to tackle it? |
I have done most of it. I have been busy these few days, but should be able to submit it later today. |
supporting has_many reification based on @lyfeyaj and @NullVoxPopuli 's works
@batter, just a reminder that the new option for the install generator has not been supported yet, not sure if this is in your agenda? |
Yes, that is on my todo list, it's been a busy day. Thanks again for all the work you did on this, super excited we got to merge this! Now I have to take care of that and a bunch of failing tests and deprecation warnings that just started showing up in the test suite since the release of ActiveRecord 4.2.0 😦 |
First, i need to say that i'm EXTREMELY excited about that PR. I was waiting for that feature since my first days with ruby. However, i'm not able to use it in a dull app. The app is here: https://github.com/mbajur/paper_trail_associations Steps to reproduce:
I'm not sure if i'm doing something wrong (it's really possible, maybe i'm too excited to stay focused and sweat is flooding my eyes!) or it's some kind of a hidden bug but it looks like paper_trail can't see my post edits (when the only modification is add/remove a tag). Thanks in advance for any clues |
@mbajur - If you look a little more closely, you should see that there has been a new join table added called There was also an update to the README with details on how to use the association tracking feature. |
Thanks for your reply batter. I've seen these things and readed them carefully but still one thing is unclear to me - are the association changes automatically included in |
I don't think association changes would automatically be included in the singular association since they are stored in a one-off association. It wouldn't make sense for |
@batter has explained better than I could have. What happened here in our project is we make sure one version of |
This is based on @lyfeyaj and @NullVoxPopuli 's works.
What I changed are mainly:
reified version for destruction, instead of remove them.
Some notes:
There is a limitation that the Reification will not work properly if the parent of a child can be changed.
Consider this scenario:
Recursive reification is not supported. Take the customer, order, and line item model for example, when a customer is reified, the line item is not reified.
Consider this scenario: