Fix User-Defined Column Cache Override #911
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
We ran into a problem where this gem was unexpectedly overriding our defined
columns
method. This was because this gem usesinstance_eval
which defines methods directly on the class.Before
Given the following schema and model, the
columns
method should reject theignored_column
:Unfortunately, invoking
acts_as_taggable
on the model after the user has definedcolumns
will override the user's method usinginstance_eval
.Solution
The solution in this PR is to user
extend
instead ofinstance_eval
, which will not override the user-defined method, and will define the intercept method as part of the inheritance ancestor walk-up.In addition, since I was confused about where to defined my test models, this PR also cleans up the definition and loading of those models. Hope this is helpful! 💜❤️🧡💛💚💙