acts-as-taggable-on
acts-as-taggable-on copied to clipboard
Ability to use tags independently from different models
This PR is based on 2 issues:
- when used on different models, tags get unified by name and
taggings_count
shows sum across all models - for a simple thing like "get all tags applicable to 1 model, not to others" we have to aggregate through taggings like group by type, use ids to select tag records and counts instead of taggings_count.
After PR we can use an option to split tags exclusively for a model
class Order < ActiveRecord::Base
acts_as_taggable exclusive: true # this will isolate order tags completely
end
# and use additional dsl to get needed tags only
ActsAsTaggableOn::Tag.exclusively_for(:order)
For further details please, see updated readme and a new spec :)
P.S. I saw find_or_create_tags_from_list_with_context in the code, but I think this hook looks kinda ugly, exclusively option makes this useless, as you can pass a tags_class
directly and it will work out of the box.
Do you like the idea of PR?
I also thought about making type
column optional and commentabe/uncommentable in migration for users which don't wont to migrate possible huge tables, but WDYT about default behaviour?
Have you tried to use context
?
https://github.com/mbleigh/acts-as-taggable-on/blob/master/lib/acts_as_taggable_on/taggable.rb#L39-L41
I think almost use case is cleared by using context
.
If you need excluding
after using context
, I think you should implement the method for negative condition of below.
https://github.com/mbleigh/acts-as-taggable-on/blob/master/lib/acts_as_taggable_on/tag.rb#L51-L55
Thanks.
@syguer you're partially right, but the drawback of context
is that it's located on taggings
, but really we need it (or I suggest type
) on tags
Please see https://github.com/mbleigh/acts-as-taggable-on/issues/700 people already complaining about that and forking because of this
I've understood it is convenient if tags have context( or type, kind). Idea looks good. But my concern is It looks complicated and decrease maintainability. Maybe, best solution is it is able to create some tags-taggings set. I want to hear maintainer's opinion.