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

Add support for custom version association class with separate database connection #46

Merged
merged 8 commits into from
Aug 31, 2024

Conversation

sobrinho
Copy link
Contributor

Fixes #45

@sobrinho
Copy link
Contributor Author

This is a draft, still needs to be tested.

@sobrinho
Copy link
Contributor Author

sobrinho commented Jul 2, 2024

@westonganger ping :)

@westonganger
Copy link
Owner

@sobrinho I don't see any documentation for this. Can you write some in the readme. Then it should be easier to review.

@sobrinho
Copy link
Contributor Author

sobrinho commented Jul 2, 2024

@westonganger added a small example to README.md.

Is that what you are looking for?

This is the same as papertrail has for the version class, we have a use case like this :

class Product < ApplicationRecord
  has_paper_trail(
    versions: { class_name: "ProductVersion" }, # papertrail has this native
    version_associations: { class_name: "ProductVersionAssociation" } # this PR will add this one
  )
end

@westonganger
Copy link
Owner

Ok looks alright. Can you also add a changelog entry for this

@sobrinho
Copy link
Contributor Author

sobrinho commented Jul 4, 2024

@westonganger added

@westonganger
Copy link
Owner

Sorry to keep asking for more. But can you actually write one or two tests for this feature?

@westonganger
Copy link
Owner

@sobrinho ping

@sobrinho
Copy link
Contributor Author

@westonganger will do today or tomorrow

@sobrinho
Copy link
Contributor Author

sobrinho commented Aug 7, 2024

@westonganger can you review this again?

I had to change the implementation a little bit and I'm not 100% sure this is in the right direction.

@sobrinho
Copy link
Contributor Author

sobrinho commented Aug 7, 2024

Even if I remove the PaperTrailAssociationTracking::VersionConcern entirely, specs still passes.

So, looks like after this we are decoupling Version and VersionAssociation entirely.

order("version_id ASC").
pluck("version_id")

model.class.paper_trail.version_class.find(version_ids)
Copy link
Owner

@westonganger westonganger Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this change could be a subquery instead of 2 separate queries. Any thoughts? (might be over-engineering)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sobrinho Any thoughts on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonganger that's intentional since Version and VersionAssociation might live in different databases.

@westonganger
Copy link
Owner

Even if I remove the PaperTrailAssociationTracking::VersionConcern entirely, specs still passes.

So, looks like after this we are decoupling Version and VersionAssociation entirely.

So that should mean we would also have the option to modify VersionAssociation to connect to a new database and not have to specify it per model? (which is good/desirable)

@sobrinho
Copy link
Contributor Author

Yes, the idea here is that version association class is a completely separate entity from the version class itself.

And if we remove the PaperTrailAssociationTracking::VersionConcern, we are still good.

@westonganger westonganger changed the title Add support to custom version association class Add support for custom version association class Aug 31, 2024
@westonganger westonganger changed the title Add support for custom version association class Add support for custom version association class with separate database connection Aug 31, 2024
@westonganger westonganger merged commit d5e15f6 into westonganger:master Aug 31, 2024
6 of 17 checks passed
@westonganger
Copy link
Owner

Merged. Thanks for your contribution.

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

Successfully merging this pull request may close these issues.

Allow to customize/extend PaperTrail::VersionAssociation
3 participants