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

Added option +taggable_model_type+ to +tagged_with+ scope #994

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sequielo
Copy link

@sequielo sequielo commented Apr 7, 2020

Context

When searching for multiple tags on different contexts on a model which is actually a table view, tagged_with will be translated based on taggable model.

On my particular case, this won't work as expected. The tags were created on the original model, not on the "table view" (this view is used for several calculations). I can't duplicate the tags on this table view as there will be a duplication of data.

Issue

ActsAsTaggableOn will translate the query based on taggable_model.base_class.name which is the name of the table view, but not the table which actually is being referenced by that table view.

Solution

I propose adding an optional parameter taggable_model_type to tagged_with method:

ProviderView.tagged_with(tags_list, on: :context, taggable_model_type: 'Provider')

By allowing to specify the taggable_model_type, the query will search tags on the correct table (and not on the view), and make the calculations on the table view as expected.

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.

1 participant