-
Notifications
You must be signed in to change notification settings - Fork 901
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 the ability to pass options to the has_many :versions association macro #1158
Add the ability to pass options to the has_many :versions association macro #1158
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Tyler, Thanks for the contribution.
People who use PT-AT have a second has_many
association.
has_many :versions, ..
has_many :version_associations, ..
We need to be clear about which association the options apply to.
So, instead of has_paper_trail(x: 'y')
, I think we should nest them, like has_paper_trail(has_many_versions_options: { x: 'y' }
.
Alternatively, we could allow people to disable the automatic definition of the association, allowing them to define the association themselves. Perhaps has_paper_trail(has_many_versions: false)
.
1aa3a37
to
ebcff7d
Compare
ebcff7d
to
cb81b27
Compare
My initial thinking was that these options should be top-level to match the existing Good point about Shouldn't one be able to assume that any options you pass to
Maybe we don't even need the word "_options" in the top-level option, since that's the only thing it could be...
Hmm. But we have other options related to the
This is what I'm leaning towards currently (and is what I just pushed up an implementation for). There is an existing This would continue to work:
but this would also now be possible:
and this:
(see new tests in This has the benefit that most of the options for the This is similar to how you can pass options to validations if you need to, or just a boolean if you don't:
That's not a bad idea, either! I'd be okay with having this as an additional option, though I think the ability to pass in an options hash gets us 90% of the way there and should be more user-friendly for most. The only case I can think of where the option path wouldn't be configurable enough is if you wanted to pass a block to the
Anyway, please see what you think of the new version I pushed up. |
cb81b27
to
43748d1
Compare
The PT-AT gem currently uses
Sounds good. Let's deprecate the old string form though, with a helpful message telling people to use the new form
Yeah, we want to be consistent. Which options would we be missing?
Cool. Let's tackle it separately though. There's already a lot going on in this PR. |
Yeah, I believe that's the only other one besides name. Sounds good. I'll follow through and push up those other changes next week.
Agreed. |
43748d1
to
302fee1
Compare
@jaredbeck Just realized we have a Would we want to change that to follow the same Or should we rationalize that inconsistency with the fact that the |
Good question. I've never understood the purpose of that feature.
So, I'd like to deprecate that feature, actually. But, let's discuss it in a separate issue, please. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is getting very close!
They are no longer using that private API. See: https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb
302fee1
to
3320bf4
Compare
Sounds good. I don't recall ever using |
All right, just pushed up the deprecation stuff. Hopefully it's done now! |
Thought of another question: If we are going to deprecate the Ironically, that might have been easier to accomplish prior to changing this from a public to private API:
because now I guess folks have to go through (Reading nested hashes is not an extremely user friendly API, but we'll at least initialize Looks like RailsAdmin is no longer using that private API, by the way, so we can remove the comment about that (I just did). Now they're using
My concern is that someone like RailsAdmin could upgrade, not see any deprecation warning, and continue to reference The code/project that sets that option and sees the deprecation warning and updates their code is going to be individual Rails applications that use those engines/libraries, not necessarily the libraries themselves like RailsAdmin. They could catch it if they had a more comprehensive test suite but the RailsAdmin test suite does not specifically have a test for that option currently (paper_trail_test.rb). I guess we just rely on people to read the |
If someone wants to do this in a separate PR, that's fine with me.
👍 they should also use their gemspec to constrain PT major versions, if they aren't already |
Thanks for your work on this, Tyler. I especially appreciate how thorough your tests are. |
Users can already customize some aspects of the
has_many :versions
association, including the association name (via:versions
option) and the class name (via:class_name
option).This changeset allows other options, such as
:extend
, to be passed on to thishas_many
.