mbleigh / acts-as-taggable-on

A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts.
http://mbleigh.lighthouseapp.com/projects/10116-acts-as-taggable-on
MIT License
4.97k stars 1.2k forks source link

inconsistency in how tags are found #287

Open meesterdude opened 12 years ago

meesterdude commented 12 years ago

I've noticed some inconsistency when querying, between using tagger and normal assignment (i.e. u.tag(u) vs. u.music_list=)

I made a user model, with ordered tags, taggers, and predefined contexts music and movies. if i have two users, m and u, and m tags u with some music, it doesn't show up under u.music. this is likewise if u assigns u music in this way. but if u assigns it as music_list then u.musiclist shows the ones assigned, but still not the other ones.

I see the sql for u.music_list looks like

 User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", 2]]
ActsAsTaggableOn::Tag Load (0.2ms)  SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = 2 AND "taggings"."taggable_type" = 'User' AND (taggings.context = 'music' AND taggings.tagger_id IS NULL)

note the

AND taggings.tagger_id IS NULL)

should it not be null OR current user id at the least? is there a reason its like this?

ghost commented 11 years ago

Noticed this too.

It seems if you use:

Tagger.tag(item, :with => tags, :on => :tags)

It creates a taggings that is assigned to the tagger, and correctly attaches the item being tagged.

The problem is though, that it doesn't update the item's tag_list.

If I tag one acts_as_taggable model via a tagger model, I can call Tagger.owned_tags item.tagged_with(tags) item.tags

but item.tag_list will be empty.

If I update item.tag_list to equal available on item.tags, I end up with multiple taggings rows in the db for the same taggable_id and tag_id, one of whom have a null tagger_id, and one of whom will have the Tagger.id as tagger_id.

I don't know if this is intentional behavior, but it seems odd.

jimishjoban commented 11 years ago

+1

This inconsistency must be removed. Or atleast the tag_list method must accept some parameters to pull all the tags (irrespective of the tagger id)

scrapcode commented 11 years ago

When object.build() is called from a chained object that is set to acts_as_tagger it is creating the object with tagger_id and tagger_type set to nil - It should set these with the acts_as_tagger objects ID.

In my case, I was using @user.tag() as well to add relationship. I was trying to list the items sorted by tag using @marks = current_user.marks.tagged_with(@tag) and it would show two iterations for each mark because there were two taggings. For the time being I've fixed this by doing @marks = current_user.marks.tagged_with(@tag, :owned_by => current_user) instead. I scanned all throughout the cost trying to find what is executed when doing a model.build(), though being a novice, was to no avail.