-
Notifications
You must be signed in to change notification settings - Fork 39
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
Allow to customize/extend PaperTrail::VersionAssociation
#45
Comments
Instead of
What happens if you use
|
I can't use ::PaperTrail::Version.connection.object_id
#=> 188700
::PaperTrail::VersionAssociation.connection.object_id
#=> 188720 Rails is also tricky at that part because it requires you to be in an abstract class to replace the connection: PaperTrail::Version.class_eval do
connects_to database: { normal: :auditing, dirty: :auditing }
end
NotImplementedError: `connects_to` can only be called on ActiveRecord::Base or abstract classes
from /Users/sobrinho/.gem/ruby/2.7.6/gems/activerecord-6.1.7.5/lib/active_record/connection_handling.rb:82:in `connects_to' We can workaround by doing that (very dirty): PaperTrail::Version.class_eval do
self.abstract_class = true
connects_to database: { normal: :auditing, dirty: :auditing }
self.abstract_class = false
end But then by using the two connection pools, FKs doesn't work in a transaction because Rails will use two separate connections thinking that they are two separate DBs. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there!
We have a separate database for
PaperTrail::Version
andPaperTrail::VersionAssociation
but we can't find a good way of implementing this.Currently we are doing something like this:
Although, this creates an issue by creating two separate connection pools:
Therefore it creates an issue with our FK between
version_associations
andversions
.To share the connection pool, we need to create an abstract class and inherit from it, like this:
While we can replace the
Version
class with a config option like this:There's no similar option for this gem.
There are explicit class directly to
PaperTrail::VersionAssociation
in the gem that could be replaced to use a config option, i.e.:paper_trail-association_tracking/lib/paper_trail_association_tracking/reifiers/has_and_belongs_to_many.rb
Line 11 in c8e8b2c
paper_trail-association_tracking/lib/paper_trail_association_tracking/reifiers/has_many.rb
Line 103 in c8e8b2c
Those could be replaced by something like or something:
In our use case, we don't need different classes per model (as supported by paper_trail) but for the application as a whole, which facilitates things here a little bit.
WDYT?
The text was updated successfully, but these errors were encountered: