Object versioning in Rails, like Papertrail but individual tables

前端 未结 2 968
不思量自难忘°
不思量自难忘° 2021-02-05 15:04

For a project I\'m currently working on I need to implement object versioning. Unfortunately I need to keep a full history of each object, so a single table solution like Paper

2条回答
  •  花落未央
    2021-02-05 15:30

    You can specify custom version subclasses with the :class_name option:

    class Post < ActiveRecord::Base
      has_paper_trail :class_name => 'PostVersion'
    end
    
    class PostVersion < Version
      # custom behaviour, e.g:
      self.table_name = :post_versions # in rails 2, use set_table_name
    end
    

    This allows you to store each model's versions in a separate table, which is useful if you have a lot of versions being created.

提交回复
热议问题