-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Tags should carry the context, not taggings #218
Comments
Can you post a gist with real life models examples and pseudo use cases. Maybe it is possible to achieve your needs w/o rewriting gem. |
Sometimes there is a use case like this: But I don't think it is necessary to change table structure So the current table list works great for the second use case, but need extra effort to achieve the first one |
@PikachuEXE i don't understand why you want specific tag to be assigned only for specific context? Maybe you are trying to achieve some goal with incorrect instruments? Explain WHY you need this. |
I don't get why it should belong only to one context. When you change name of tag in this form NEW tag would be created and old one will remain in table. |
tag itself does not belong to anything. So you can't say tag belongs to smth, it is independent entry. When you tag some category with Tag named solo, than Tag with name solo created. When you change this category.tag_list to "solo2", new Tag is created, and associated with that category. Old Tag with name 'solo' still in db. When you do another_category.skill_list = "solo", new Tag entry is not created but used old one. When you do one_more_another_category.some_other_list = "solo", also no new Tag entry is created, old Tag with "solo" is used. If you need to find categories for particular context you can do it. |
I am just saying there is use case that has such constraint, I am just interested if the first use case can be done |
manage all tags in all context in one box - is not doable. You can monkey patch gem to achieve that. |
I see |
I have run into the OP's first use case as a limitation as well. For the second, using a subclass for custom behavior would be the logical thing to do -- what might be great though is if class Topic < ActsAsTaggableOn::Tag
has_many :follows, :as => :followable
has_many :followers,
:through => :follows,
:source => :user,
:class_name => 'User'
end
class Discussion < ActiveRecord::Base
acts_as_taggable_on :topics
end This works fine for calling methods off of @discussion.topics.first.followers # => NoMethodError for ActsAsTaggableOn::Tag |
Cool, fixed the above easily enough by simply manually overriding after the class Discussion < ActiveRecord::Base
acts_as_taggable_on :topics
has_many :topics, :through => :topic_taggings, :source => :tag, :class_name => "Topic"
end I'll see about getting a pull request whipped up to make this an option. |
@ches looking forward. |
My use case for having context in the tags table is as follows. I have a model that has many tag sets to store attributes about a Driver class Driver < ActiveRecord::Base
acts_as_taggable_on :equipment_skills, :benefits, :preferences
end All of these have predefined allowable values for them. However in order to facilitate it I have to have another model that simply lists tags & contexts. Now, initially that seems ok, as the UI can just pull from the "AllowedTags" model when presenting the UI.. However it can complicates certain query types such as tag_counts. As ideally [the customer] would like to see all available skills, even if no one has it (thus count 0). Moving context to the tags model, however does add increased db storage overhead, and possibly db load in doing some queries. And the original use case of this issue is kinda neat as well. e.g. in a "freely" tagged tag type, being able to add attributes to that tag after-the-fact. e.g. colors, icons, etc.. Now I could see that being done with a secondary model with a has_one or has_many join against tags. and the secondary model would either be only for a specific context (has_one), OR would have a :context field (has_many). then all the application specific attributes could be placed within the application model and not the gem model. (probably cleaner approach for forward compatibility with the gem). Some niceties that would help make some of these happen easier is, having an options of :class_name to the acts_as_taggable_on model method to allow overriding the child class for a relationship (@ches's use-case) or somehow having the "easy" ability to define relative associations on the core models.. e.g. a "tag_details" model kind of thing maybe. Anyways, just some thoughts on the topic.. and thank you VERY Much for this wonderful gem in the first place.. |
Adding STI behavior only covers usecase 2 if the unique-constraint on the tags is expanded to <type,name> instead of just as it may be necessary to have a tag of the same name in different contexts (i.e. subclasses). |
For a very good example of use cases where tags would belong to specific categories (rather than the tagging) see drupal's concept of 'vocabulary'. This isn't to promote it in anyway, it's just that there's a ton of very useful information on the subject. |
I am closing this issue for now. I think the focus of acts-as-taggable-on should remain in providing tagging functionality that everyone is familiar with. That is to say, freely adding words to a piece of content. The use case described is certainly a valid one, but I think it too specific to be included in this gem. If you require such a functionality, in my opinion you must put it in your own models and not rely on a plugin. By writing your own models, you are signaling the importance of what you want. And hopefully you are adding tests for it too. |
Proposal: The context field should be stored in the
tags
table instead of thetaggings
.Usecase 1: Predefining Tags for a specific context and suggesting them to the user.
Usecase 2: Augmenting the Tag class by adding color or image fields to make the way a tag is displayed configureable. Or to add descriptions to a Tag.
Neither is currently possible because identically-named tags from different namespaces share the same Tags record, even if they have semantically completely different meanings and just coincidentally happen to have the same name.
The text was updated successfully, but these errors were encountered: