0
+# Reopen the article model and wang in the stuff we need.
0
+ # We define this tags attribute so when the form posts, the params for
0
+ # tags get set, and we can subsequently access it later on.
0
+ attr_accessor :tag_list
0
+ # Datamapper's version of has_many :through. Not quite as pretty, but it'll get the job done. Or not...
0
+ # This is supposed to work but it just returns a #<DataMapper::Support::TypedSet[Tag]: {}>
0
+ # has_and_belongs_to_many :tags,
0
+ # :join_table => "taggings",
0
+ # :left_foreign_key => "article_id",
0
+ # :right_foreign_key => "tag_id",
0
+ return if @tag_list.nil? || @tag_list.empty?
0
+ # Wax all the existing taggings.
0
+ self.taggings.each {|t| t.destroy! }
0
+ @tag_list.split(",").each do |t|
0
+ # Hmm, can we do transactions with DM? I'm sure there's a way.
0
+ tag = Tag.create(:name => t.strip)
0
+ Tagging.create(:article_id => self.id, :tag_id => tag.id)
0
+ after_save do |article|
0
+ # This is probably slower than habtm, but that's not working as stated above.
0
+ taggings.map { |tagging| tagging.tag.name }.join(", ")
Comments
No one has commented yet.