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

Change version association database and table name. #16

Open
phrsouza opened this issue Apr 22, 2020 · 5 comments
Open

Change version association database and table name. #16

phrsouza opened this issue Apr 22, 2020 · 5 comments

Comments

@phrsouza
Copy link

I'm trying to use papetrail and papetrail association track storing its data into a different database.

I achieved that for the PaperTrail::Version model by following the papetrail doc

I saw the following comment on the PaperTrail::VersionAssociation class:

  # This is the default ActiveRecord model provided by PaperTrail. Most simple
  # applications will only use this and its partner, `Version`, but it is
  # possible to sub-class, extend, or even do without this model entirely.
  # See the readme for details.

But I'm not quite sure how to change the behavior of the PaperTrail::VersionAssociation as I did in the PaperTrail::Version.

I also posted this question on stackoverflow

@westonganger
Copy link
Owner

I appreciate that you asked this question in the issues section and want to encourage that.

It is likely this functionality has not been implemented and will likely require a PR to achieve the functionality you desire. If you would like to take a stab at this it let me know, otherwise I will try to take a look into this when I have time and see what I can come up with.

@phrsouza
Copy link
Author

@westonganger I believe that this is not a priority since we have a workaround that is patching the Papertrail::VersionAssociation in a initializer:

#config/initializers/paper_trail.rb

PaperTrail.config.track_associations = true

PaperTrail::VersionAssociation.class_eval do
  self.table_name = 'version_associations'
  connects_to database: { writing: :versions_db, reading: :versions_db }
end

@westonganger
Copy link
Owner

Yes I understand, however someone may want to use different databases per model. We should be able to support this case.

@tommy-gilligan
Copy link

tommy-gilligan commented Apr 14, 2021

Love this solution. Unfortunately it is broken in Rails 6.1:

"`connects_to` can only be called on ActiveRecord::Base or abstract classes" 

I think per model configuration would be ideal but as far as I can tell there is no other per model configuration yet (so a bit trickier to get going with a PR). The main point of integration as far as app models are concerned is the has_paper_trail method defined in the base paper trail gem and not this extension gem, so not sure how to add to it here.

I'm thinking of adding an abstract class that is parent of VersionAssociation and child of ActiveRecord::Base to resolve this. I'm guessing that when client applications extend VersionAssociation it is mostly for reasons other than selecting a different database (the class hierarchy I'm describing is to avoid breaking things for the majority).

@sobrinho
Copy link

Same issue here, we used to patch the model but it doesn't work on 6.1 anymore. Any hints?

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

4 participants