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
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to