Comments (7)
ruby-1.9.2-p180 :011 > post = NewsPost.new(:name => '1', :text => '1', :rubric_id => 100)
=> #<NewsPost id: nil, rubric_id: 100, name: "1", thread_id: nil, genre: nil, region_id: nil, published_at: nil, annotation: nil, text: "1", album_id: nil, video_id: nil, source: nil, source_url: nil, author_name: nil, author_email: nil, exclude_from_rss: nil, main_in_rubric_from: nil, main_on_site_from: nil, authorship: nil, commentable: false, weight: 5, links: nil, old_id: nil, views_count: 0, created_at: nil, updated_at: nil, creator_id: nil, updater_id: nil, storyline_id: nil, locked_by: nil, visibility: nil, post_image_file_name: nil, post_image_content_type: nil, post_image_file_size: nil, post_image_updated_at: nil, type: "NewsPost", image_title: nil, author_id: nil, image_description: nil, image_author: nil>
ruby-1.9.2-p180 :012 > post.save
=> true
ruby-1.9.2-p180 :013 > Version.last
=> #<Version id: 40, item_type: "Post", item_id: 230755, event: "create", whodunnit: nil, object: nil, created_at: "2011-07-07 11:39:02">
ruby-1.9.2-p180 :014 > post.destroy
=> #<NewsPost id: 230755, rubric_id: 100, name: "1", thread_id: nil, genre: nil, region_id: nil, published_at: nil, annotation: nil, text: "1", album_id: nil, video_id: nil, source: nil, source_url: nil, author_name: nil, author_email: nil, exclude_from_rss: nil, main_in_rubric_from: nil, main_on_site_from: nil, authorship: nil, commentable: false, weight: 5, links: nil, old_id: nil, views_count: 0, created_at: "2011-07-07 11:39:02", updated_at: "2011-07-07 11:39:02", creator_id: nil, updater_id: nil, storyline_id: nil, locked_by: nil, visibility: nil, post_image_file_name: nil, post_image_content_type: nil, post_image_file_size: nil, post_image_updated_at: nil, type: "NewsPost", image_title: nil, author_id: nil, image_description: nil, image_author: nil>
ruby-1.9.2-p180 :015 > Version.last
=> #<Version id: 41, item_type: "NewsPost", item_id: 230755, event: "destroy", whodunnit: nil, object: "---\nalbum_id: !!null \nannotation: !!null \nauthor_em...", created_at: "2011-07-07 11:39:47">
from paper_trail.
Please could you post a code snippet showing the error in logic?
from paper_trail.
if i take code above, we got 2 versions with id 40 and 41, they should belong to a single object with id 230755, but htey dont, because they got item_type: "Post" and item_type: "NewsPost", so if i say
Version.find(40).next #=> nil
Version.find(41).previous #=> nil
to repeat this on new application we need:
rails new sti
cd sti
[install papertrail]
rails g model post name:string type:string && rake db:migrate
rails g model news_post --no-migration --parent=Post # not sure about params, but they should be like this
go to post.rb and add has_paper_trail
rails c
post = NewsPost.new(:name => '1')
post.save
post.name = '2'
post.save
post.destroy
in versions we will have:
create Post
update Post
destroy NewsPost
and destroy version will be isolated from other versions
from paper_trail.
they all should have the same item_type. according to rails philosophy, they should be NewsPost (actual name of model), but we can face an application, where User < AR, Admin < User and if some user becomes an admin, and then back to common user - versions will be separated and messed up, so, to avoid this, they all should be named like parent model
from paper_trail.
in record_destroy
:item_type => self.class.name,
changed to
:item_type => self.class.base_class.name,
fixes an issue, works correctly for both non-sti and sti model... but needs to be tested.
tell me if you will fix it in gem, so i can update. right now i just roughly edited gem sources, any update will destroy my changes :(
from paper_trail.
Thanks for the instructions on how to reproduce this bug. It was introduced in commit f685c92 and my tests didn't catch it.
Rails's approach to STI is to store the name of the base class as per your last comment (but not your penultimate comment). I'm updating the code now and adding a test to lock it in.
from paper_trail.
This is fixed in v2.2.6.
from paper_trail.
Related Issues (20)
- n+1 when iterating over change sets HOT 1
- paper_trail railtie initializer loading after Rails config initializers HOT 1
- frameworks/rspec inclusion leaks state between examples HOT 2
- Unable to use non-primary database for versions table in Rails 7 HOT 2
- Store encrypted values on object_changes column HOT 14
- Update YAML->JSON suggested solution in `README.md`. HOT 2
- paper_trail.update_columns is setting an incorrect Version#created_at value HOT 1
- paper_trail:install requires a db connection HOT 1
- Version table should use uuid as id when generating a migration HOT 2
- PaperTrail with Rails 7: history index and history show not showing any data HOT 2
- User must exist error HOT 2
- Error log doesn't provide valuable output. HOT 2
- Make created_at dependence on record#updated_at configurable HOT 1
- The reified model attribute is null if the column type is time HOT 1
- Redefinition of PaperTrail::Version stopped working in v12/v14 with Rails 6.1 using Zeitwerk HOT 3
- Records with serialized attributes with both database and model defaults throw serialization errors HOT 3
- Track timestamp of destroy event HOT 2
- changeset shows no changes,but it's created HOT 2
- Wrong attributes are stored for encrypted attributes HOT 6
- Silenced failures on yaml parsing with an empty changeset HOT 2
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.