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

Make version reification_class use Rails' customization on polymorphism #1493

Open
fsuchan opened this issue Sep 6, 2024 · 1 comment
Open

Comments

@fsuchan
Copy link

fsuchan commented Sep 6, 2024

Problem

Rails has a built-in way to customize polymorphic_type, there's a good read about it here. In a nutshell, a namespaced model such as User::Model can be stored in database using polymorphic_type user, decoupling namespacing (architecture) from database.

PaperTrail heavily relies on polymorphism and by default breaks when customizing. Specifically: In the example from above version.reify throws an error: wrong constant name user.

Solution

Looking into PaperTrail's code we found that reifier.rb simply constantizes item_type.

This line can be improved by changing it to: clazz = version.class.polymorphic_class_for(version.item_type)

Alternatives

We currently patched this line in our own code, works.

@gurgelrenan
Copy link
Member

Hi @fsuchan,

Feel free to submit a P.R whenever you're ready. We're looking forward to reviewing it!

Thanks!

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