2013-04-21 8 views
0

我已經實現了博客,我有文章和標籤之間的許多到許多關聯。當文章被製作時,它會有一對多的標籤。當我從我的應用程序中刪除文章時,它刪除了其關聯的標籤。我已經設置了刪除文章不會刪除其在軌道上的紅寶石相關標籤

has_many :taggings, :dependent => :destroy 
    has_many :tags, through: :taggings , :dependent => :destroy 

像這樣在article.rb(模型)。我需要做別的事情嗎?

tag.rb

class Tag < ActiveRecord::Base 
    attr_accessible :name 
    has_many :taggings 
    has_many :articles, through: :taggings 
end 

在其相關的文章是從數據庫中刪除如何獲取標記刪除。任何建議。

回答

0

在你tag.rb,使用

belongs_to :article 

,而不是你的當前設置

+0

嗨,如果我用你的建議,它會破壞我有很多通過關係。不是 ?文章和標籤之間有很多關係。 – 2013-04-21 20:24:53