Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Missing doc] How to generate the table for Custom Version Classes? #303

Closed
qwert321 opened this issue Nov 28, 2013 · 2 comments
Closed

Comments

@qwert321
Copy link

With README(v3.0.0rc), section "Custom Version Classes", I didn't find any text about how to generate the database table for Custom Version Classes.

  1. Need I run some rake script to generate migration script, then run the migration script?
    then, what's rake commands to do it?
  2. Or the same fields for Custom Version Classe table as for the model table?
  3. Or the same fields for Custom Version Classe table as for the generic Version table?

Thanks

@batter
Copy link
Collaborator

batter commented Nov 29, 2013

As that section of the README insinuates, one way to do it is to create a migration that is identical to the one PaperTrail generates for your versions table, and then use that (number 3 in your suggested methods). Another easy way to do it would be to use Single Table Inheritance, and make your custom version class a sub-class of the PaperTrail::Version class. Simply add an extra field to your migration for the versions table like so:

t.string     :type

And then subclass your custom version model under the PaperTrail::Version class like the README suggests, but don't use the self.table_name option on the model. Rails will then know to use the type column as the indicator for which type of version your using. (But this will result in all version types being stored in the versions table, which may not be desired). Those are the options that I would recommend.

Here is an example in the test suite of one way to generate a custom versions table.

@batter batter closed this as completed Nov 29, 2013
@batter
Copy link
Collaborator

batter commented Dec 3, 2013

Oh, there is also a 3rd way to make a custom version class, and that involves using the new PaperTrail::VersionConcern module. Please see the discussion on #289 for more details about usage of that module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants