2010-04-04 7 views
1

has_many : through 관계가있는 많은 제품이있는 상점 모델이 있습니다.레일, accepts_nested 및 has_many : through는 중복 항목을 만듭니다.

나는 이것을 accepts_nested_attributes와 함께 작업했지만 결과적으로 레일스는 중복 된 연관을 만들고있다.

나는 특별한 일이 없다. 아주 간단한 앱이다.

중복 된 동료가 생성되는 이유에 대한 아이디어가 있습니까?

+0

을 통해 지금까지 쓰기 코드를 게시하시기 바랍니다. – Salil

+0

좀 더 자세히 살펴보고 게시하겠습니다. 아무도 버그를 아는 지 확인하는 중이었습니다 – s84

+0

우연히 페이지를 새로 고친 다음에이 작업이 수행됩니까? – Lukas

답변

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 
관련 문제