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 to custom version association class #46

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

sobrinho
Copy link

Fixes #45

@sobrinho
Copy link
Author

This is a draft, still needs to be tested.

@sobrinho
Copy link
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
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
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
Author

@westonganger will do today or tomorrow

@sobrinho
Copy link
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
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)

@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
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.

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