Comments (8)
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.
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.
and I've mistakenly pushed to comment and close button....
from paper_trail.
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.
No problem, I'm making you wait, so should you
from paper_trail.
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.
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.
Closing because it's gone quiet. Please re-open if you like.
from paper_trail.
Related Issues (20)
- The "paper_trail" initializer is not guaranteed to execute before the "load_config_initializers" initializer HOT 1
- Add Proc to skip HOT 4
- Change the Versions table name HOT 4
- Support Rails 7.1 HOT 5
- Drop RequestStore in favor of ActiveSupport::CurrentAttributes HOT 6
- errors are not raised when update, update_columns, or destroy versions fail to create HOT 2
- Install migrations --with-changes use text column but PaperTrail errors with expecting JSON or JSONB HOT 1
- `versions` association adding an additional and invalid ORDER BY statement HOT 3
- Only track changes for updates; still track creation and destruction events HOT 3
- Incompatible with ActiveRecord 7's composite primary keys HOT 4
- Ignore certain columns by default HOT 2
- yaml_column_permitted_classes warning never actually gets output HOT 2
- `PaperTrail::Version.where_object` cannot not find serialized values in YAML object HOT 1
- Date/DateTime leads to empty changeset HOT 2
- Ability to conditionally set metadata on a version record depending on the event (create, update, etc)
- `versions` raises error whenever `PaperTrail::Version` is a parent to an abstract superclass
- Empty "update" versions when using active storage HOT 3
- errors are not raised when update, update_columns, or destroy versions fail to create
- reify tries to set the value for a read_only attribute HOT 1
- Tests fail on master - rspec ./spec/paper_trail/request_spec.rb:120 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from paper_trail.