Giter VIP home page Giter VIP logo

Comments (7)

nir0 avatar nir0 commented on May 24, 2024
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.

airblade avatar airblade commented on May 24, 2024

Please could you post a code snippet showing the error in logic?

from paper_trail.

nir0 avatar nir0 commented on May 24, 2024

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.

nir0 avatar nir0 commented on May 24, 2024

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.

nir0 avatar nir0 commented on May 24, 2024

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.

airblade avatar airblade commented on May 24, 2024

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.

airblade avatar airblade commented on May 24, 2024

This is fixed in v2.2.6.

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.