Polymorphic question w/r/t acts_as_taggable plugin use

I’ve been using the acts_as_taggable_on_steroids plugin successfully
for awhile with models descended directly from ActiveRecord, but just
ran into something strange in a new use case where I have models that
are subclasses of other models.

I’m looking for an explanation and a workaround or correction to the
way I’m doing things and it occurs to me that someone may have an
answer if they have good knowledge about rails’ polymorphic operation
OR about the way acts_as_taggable works…

Here’s my problem -

  1. Models -

class Group < ActiveRecord::Base

class Circle < Group

class SupportCircle < Circle

  1. I have Circle declared as acts_as_taggable

  2. when I tag a Circle, the ‘taggings’ table record for it has ‘Group’
    for the ‘taggable_type’ column

Q1: why isn’t it ‘Circle’ for the ‘taggable_type’?
Q2: where in the code is this assignment of the value done? (I can’t
seem to find it and assume it’s some “under the covers” magic that
Rails is doing…?)

  1. acts_as_taggable.rb’s ‘find_tagged_with’ method does the query
    with a join that has this fragment:

AND #{table_name}_taggings.taggable_type = ‘#{name}’

So, when I do a search for Circle objs tagged with a tag, it fails to
find those tagged objs because when I call
Circle.find_tagged_with(tag), the ‘name’ is coming in as ‘Circle’
while the entry in the table is ‘Group’ as described above.

Q3: why is the search value inconsistent with the ‘tagging’ insert’s
assignment of value for ‘taggable_type’?

  1. I want to start tagging SupportCircle’s and not sure of a few
    things…

Q4: with an acts_as_ declaration, do I need to explicitly declare that
in a subclass or will SupportCircle be taggable because Circle is
declared so?
Q5: if I want to distinguish between Circles and SupportCircles in my
searches, I do separate calls for each with
Circle.find_tagged_with(tag) and SupportCircle.find_tagged_with(tag)
respectively, and from the look of that query, I’ll only get Circles
from the first and SupportCircles from the second, right? (yes, I
think… just checking 'cause of the unexpected behaviors I’m seeing)


Sorry for the length of this and all the questions, but as I said
above, perhaps some of you will know specifics of acts_as_taggable and
others may now the general Rails answers and that will help me figure
out how to make what I want to do work.

Thanks in advance.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs