[Nitro] Bug in Taggable and .delete_all_tags

George Moschovitis george.moschovitis at gmail.com
Mon Aug 28 12:41:09 EDT 2006


btw, *please* add [PATCH] in the  subject of email containing patches
so I can better track them.

thanks,
George.

On 8/28/06, Jonathan Buch <john at oxyliquit.de> wrote:
> Hi,
>
> bug in taggable in 0.40.
>
> a1.delete_all_tags
> assert_equal 0, a1.tags.size
>
> assert_equal 4, Tag.count # << raises, sais 3
>
> While writing that and debugging while doing it I found the bug in
> taggable.  The problem is, that the 'tags' array and the tags inside don't
> get reloaded, even if a new tag was added and incremented the `.count`.
> Solution would be, to add a `tag.reload` before doing the `tag.unlink`.
>
>    def delete_all_tags
>      for tag in tags
>        tag.reload
>        tag.unlink
>      end
>      tags.clear
>    end
>
> Not sure if I like it, it's not really efficient, too many roundtrips to
> DB.  Hypothetically: could `Tag` (or any other entity) be told to always
> return the "same" (same `.object_id`) Object instead of a new one?  The
> information would be shared then and wouldn't have to be reloaded, but I'm
> really not sure how this would work, I guess one would need caching...
>
> A side note: should `.reload` return the object instead of a Fixnum as it
> does right now?
>
> Anyway, attached is a patch which adds the reload and the test case, nasty
> thing took me quite some time to find out why it deleted every tag and not
> just the 2, wasted time ;/
>
> Jo
>
> --
> Feel the love
> http://pinkjuice.com/pics/ruby.png
>
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
>
>
>


-- 
http://www.gmosx.com
http://www.nitroproject.org


More information about the Nitro-general mailing list