Giter VIP home page Giter VIP logo

Comments (8)

airblade avatar airblade commented on May 18, 2024

Please could you post a short gist / code snippet demonstrating the problem? I.e. what you expect to happen and what actually happens. That'll help me figure out the problem for you.

Thanks,
Andy

from paper_trail.

saifis avatar saifis commented on May 18, 2024

thanks for the reply, I've been looking into the code but was still unable to find a reason.

What I am doing is using the paper_trail gem to create a table that has a serialized array in it.
Model A
serialize :xxx

Controller
a = A.new
a.xxx = {large array}
a.save

--later
b = A.find(a's id)
b.xxx = {edited large array}
b.save

To my understanding this should make 2 versions entries, one as head, which contains nothing, and another that stores the version I made with instance a,
however, when I try loading this version and call noify, the xxx Array is not of the original, but is the edited one. I call the version as so

version = Versions.find( origin_id )
a = version.next.noify

Am I just doing this wrong?

I am sorry to be irresponsible but have become very busy at the moment, and may not be able to commit my efforts adequately, but will try to give all the information needed. I'll try to strip the sensitive info out and make a better example.

from paper_trail.

saifis avatar saifis commented on May 18, 2024

and I've mistakenly pushed to comment and close button....

from paper_trail.

airblade avatar airblade commented on May 18, 2024

It sounds like you're doing it right. When a is created, the version written won't contain anything. When b is saved, the version written will store a's attributes -- just as you said. And it looks like you're getting a array correctly.

I'll look into this for you, but I'm very busy like you and I probably won't get a chance for several days (and then I'm away on holiday for a week)...

from paper_trail.

saifis avatar saifis commented on May 18, 2024

No problem, I'm making you wait, so should you

from paper_trail.

saifis avatar saifis commented on May 18, 2024

I think I found out a way to recreate my problem, the problem was is that the serialized Array I had inside the paper_trailed model was nested and included hashes inside,and the changes inside the hashes do not seem to be recognized as changes.

here is the gist for what I typed in
https://gist.github.com/753029

The reason why the original was getting overwritten was because I had another attribute, which was a normal string inside AAA, which I was updating as well, which would cause a new version to be made, however paper_trail would not notice that aa.foo was changed, and would save over it. thus altering the original.

Now, having such an ugly thing inside a database is truly just poor design, but thats another story.

Hope this helps you.

from paper_trail.

airblade avatar airblade commented on May 18, 2024

PaperTrail uses ActiveModel::Dirty's changed? method to detect whether any attributes have changed. Its documentation says it can't automatically track changes to attributes modified in-place, so for those you have to tell ActiveModel about the change.

I think this is why your modification (aa.foo[0][:cc]["foo"] = "barbar") is not causing a new version to be saved. However I'm not too sure what I can do about this.

from paper_trail.

airblade avatar airblade commented on May 18, 2024

Closing because it's gone quiet. Please re-open if you like.

from paper_trail.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.