mongoid_taggable_with_context icon indicating copy to clipboard operation
mongoid_taggable_with_context copied to clipboard

Tag counter in parent model

Open christianhager opened this issue 13 years ago • 4 comments

Hi, thanks for this great tool! A true time-saver. I was also looking for a way to scope the tag-counter into some parent model.

In addition to Account.tags_with_weight

I want to do current_account.tags_with_weight

I came up with this

class Account
      include Mongoid::TaggableWithContext::RealTimeCounter
      count_tags_for :tags
end

Then in the taggable model you can do this:

class MyModel
     include Mongoid::TaggableWithContext
     include Mongoid::TaggableWithContext::AggregationStrategy::RealTime

     belongs_to :account
     taggable :tags, :counter_in => :account
end

What do you think about the idea? I would gladly push some code, but had some trouble getting the specs to run as it needs mongo 1.8. I will try to get that sorted out, but would love to hear your thoughts on the idea first.

christianhager avatar Aug 20 '11 10:08 christianhager

I think this is a similar issue as #10 if I understand correctly. Can you elaborate a bit more on what you are trying to accomplish? Specifically, what kind of data are you trying to aggregate? per user, per model, and per context tagging?

aq1018 avatar Dec 20 '11 08:12 aq1018

some sort of tagger functionality?

aq1018 avatar Dec 20 '11 08:12 aq1018

If I understand correctly think the account model is a tagger, and you want to aggregate based on tagger information as well.

I'm thinking about how best to represent the taggable, tagger, and tags in mongo db. Will probably implement something pretty soon.

aq1018 avatar Jan 28 '12 09:01 aq1018

Sorry for my late reply! I want to be able to store the weight of tags in another model. I created a solution based on your gem to solve this, but I think the aggregation is way to costly in my implementation. I also added support to add more meta then just the counter. Perhaps you want to take a look at it: https://github.com/christianhager/mongoid_tag

Its not a good idea to create a gem that is almost a copy of yours, but I wanted to learn how to make a gem as well.

christianhager avatar Jan 28 '12 13:01 christianhager