2010-04-04 38 views
1

我有一個存儲模型,其中has_many:through關係有許多產品。rails,accepting_nested和has_many:通過創建重複條目

我有這方面的工作與accep_nested_attributes,但結果是,導軌正在重複關聯。

我沒有什麼特別的,它是一個非常簡單的應用程序。

關於爲什麼重複聯繫人正在創建的任何想法?

+0

請把你的代碼,你寫那麼遠。 – Salil 2010-04-04 05:34:46

+0

讓我再努力一下,然後我會發布。我只是檢查是否有人知道一個錯誤 – s84 2010-04-04 06:22:31

+0

這是否會在任何機會刷新頁面後出現? – Lukas 2010-04-05 15:04:24

回答

1

看看回答:how to avoid duplicates in a has_many :through relationship?這裏:

附加:uniq的=>真到了的has_many:通過

class Blog < ActiveRecord::Base 
has_many :blogs_readers, :dependent => :destroy 
has_many :readers, :through => :blogs_readers, :uniq => true 
end 

class Reader < ActiveRecord::Base 
has_many :blogs_readers, :dependent => :destroy 
has_many :blogs, :through => :blogs_readers, :uniq => true 
end 

class BlogsReaders < ActiveRecord::Base 
    belongs_to :blog 
    belongs_to :reader 
end