I’m using acts_as_taggable which provides a polymorphic join table
(taggings) between a Tag and some other class of object (Resource in
this case). Tagging has the fields “tag”, “taggable_id” and
“taggable_type”. I’m in rails 2.2.2.
I’m trying to set it up so that the same object can’t be tagged with the
same tag twice. According to the api, this is as simple as setting
:uniq => true on the has_many :through association. But, this doesn’t
work for me. I tried setting it on the main association instead/as
well, but no combination (of putting uniq on either or both
associations) seems to work.
#in Resource
has_many :taggings, :foreign_key => “taggable_id”, :dependent =>
:destroy, :uniq => true
has_many :tags, :through => :taggings, :uniq => true
I can get the join record to fail validation if it’s a duplicate of an
existing record, like so:
#in Tagging
validates_uniqueness_of :tag_id, :scope => [:taggable_id,
:taggable_type]
But, i’d like to get the uniq option working so that it just silently
doesn’t add the duplicates rather than raising validation errors.
Can anyone help?
thanks, max