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

Fix tracking subclasses with additional fields #237

Merged
merged 2 commits into from
Apr 1, 2020

Conversation

cgriego
Copy link
Contributor

@cgriego cgriego commented Apr 1, 2020

If you have subclasses with their own fields, none of those fields are being tracked because the options will only look at the parent class' fields. For example:

class Person
  include Mongoid::Document
  include Mongoid::History::Trackable

  track_history
  field :name, type: String
end

class Employee < Person
  field :job_title, type: String # this would never be tracked
end

This worked prior to this commit: 774dd0d

@coveralls
Copy link

coveralls commented Apr 1, 2020

Coverage Status

Coverage increased (+0.004%) to 99.378% when pulling c00e6c7 on getaroom:fix-subclass-tracking into 3f98e77 on mongoid:master.

Copy link
Collaborator

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Thank you! Thoughts on below?

@@ -14,44 +14,44 @@ def scope

def prepared
@prepared ||= begin
@prepared = options.dup
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks strange. Change it to:

return if @prepared 

@prepared = ...

Generally I am a bit concerned that we are now making assignment of prepared and modifying it all over the place. Is there a way to fix the issue without doing that change and keep gathering settings and returning modified version from functions, then calling merge on the results?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really feel like the library took a turn down a wrong path with the linked commit and I'm just trying to make the best of it. @options was assigned and modified all over the place already, I just switched it so the original options could be retrieved. Another direction I considered was having Options keep and expose the original_options and leave it modifying @options and using @prepared in the same way it does now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like keeping original_options, feels cleaner, no?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also I am fine with the code as is. LMK when you want to merge (on green).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an uglier changeset in the commit, but it feels a little cleaner to me to in the end to keep the mutation done by prepared isolated to @prepared instead of @options.

The Travis build is green, but neither time has it updated the GitHub status. 😕

@dblock dblock merged commit 5590d69 into mongoid:master Apr 1, 2020
@dblock
Copy link
Collaborator

dblock commented Apr 1, 2020

LGTM, merged

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.

3 participants