Skip to content

Instantly share code, notes, and snippets.

@royw
Created September 19, 2009 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save royw/189598 to your computer and use it in GitHub Desktop.
Save royw/189598 to your computer and use it in GitHub Desktop.
class Tagset
include DataMapper::Resource
include DataMapper::Timestamp
include DataMapper::Serialize
property :id, Serial
property :name, String, :index => true, :nullable => false
property :select_mode, Boolean, :index => true, :default => true
property :asserted_tags, Text, :default => '', :lazy => true
property :created_at, DateTime
property :updated_at, DateTime
belongs_to :view, :nullable => true
has n, :tags, :through => Resource
##
# deassert the Tag with the given Tag name
#
# @param [String] name the name of a Tag object
def deassert_tag(name)
@@logger.debug{"deassert_tag(#{name})"}
tag = self.tags.first(:name => name)
unless tag.nil?
joins = TagTagset.all(:tag_id => tag.id, :tagset_id => self.id)
joins.each do |join|
@@logger.debug{"destroying join TagTagset.all(:tag_id => #{tag.id}, :tagset_id => #{self.id})"}
join.destroy
end
self.save
self.tags.reload
joins = TagTagset.all(:tag_id => tag.id, :tagset_id => self.id)
unless joins.blank?
@@logger.warn{"failed to deassert_tag(#{name}) joins => #{joins.inspect}"}
end
end
end
end
When ran:
deassert_tag(OK)
destroying join TagTagset.all(:tag_id => 47, :tagset_id => 1)
failed to deassert_tag(OK) joins => [#<TagTagset @tagset_id=1 @tag_id=47>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment