2011-10-29 6 views
0

Mongoid, Rails 및 Fabrications를 사용하고 있으며 이러한 상황이 어떻게 발생하는지 전체적으로 알 수 있습니다. 모든 생각은 매우 감사하지만, 나는 이것을 매우 복잡하게 생각합니다. 난 그냥 사용자를 조작하고 합류 그룹을 4 개 가지고 싶지만 8 개가 계속로드됩니다. (여기서Association에서 생성 한 중복 레코드

 
#<PolcoGroup _id: 1 ... member_ids: [], follower_ids: []> 
#<PolcoGroup _id: 1 ... member_ids: [], follower_ids: []> 
#<PolcoGroup _id: 1 ... member_ids: [], follower_ids: []> 
#<PolcoGroup _id: 1 ... member_ids: [], follower_ids: []> 
#<PolcoGroup _id: 1 ... member_ids: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], follower_ids: [1, 1]> 
#<PolcoGroup _id: 1 ... member_ids: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], follower_ids: [1, 1]> 
#<PolcoGroup _id: 1 ... member_ids: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], follower_ids: [1, 1]> 
#<PolcoGroup _id: 1 ... member_ids: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], follower_ids: [1, 1]> 

: 나는 4를 얻을 @user1.joined_groups.size 내가 실행,하지만 난 @user1.joined_groups.map(&:name)을 수행 할 때, 나는 여덟 개 기록을 얻을 때 여기

내 코드

 
@user1 = Fabricate.build(:registered) 
 
@user1.joined_groups << [common_group, 
          cali_group, 
          ca46, 
          Fabricate(:polco_group, {:name => "Gang of 13", :type => :custom})] 

의 관련 섹션 모든 BSON :: ObjectId ('4eab3ca5f11aac2701000009') 문장을 1로 대체하고 중간 코드를 많이 제거했습니다.

전체 코드 집합은 여기에서 볼 수 있습니다. https://gist.github.com/1323984

간단히 말해서지도를 호출하는 대부분의 문자가 문제의 원인 일 수 있습니다.

 
    puts "just created user with these groups:" 
    puts @user1.joined_groups.map(&:name) 
    puts "then secondly" 
    puts @user1.joined_groups.map(&:name) 

이를 생성합니다 (!) : 어떤 통찰력에 대한

 
just created user with these groups: 
Dan Cole 
CA 
CA46 
Gang of 13 
then secondly 
Dan Cole 
CA 
CA46 
Gang of 13 
Dan Cole 
CA 
CA46 
Gang of 13 

감사합니다! 반복 된 시도 후에, 나는 이것을 복제하는 방법을 알아낼 수 없다. 그래서 나는 Fabrication 보석을 의심하고있다.

팀 나는 문제가 단순히 올바르게 사용자에 그룹을 밀어되지 않는다는 것 같아요

+0

와우 - 다시이 문제에 부딪 혔습니다. http://stackoverflow.com/questions/27697076/mongoid-association-creating-unwanted-records – bonhoffer

답변

1

: (업데이트 아니, 내가 표준 mongoid 물체와 함께이 오류가, 그래서 나는 완전히 mongoid을 비난하고있다.). concat을 사용해 보거나 별도로 삽질하십시오.

@user1.joined_groups.concat([common_group, 
         cali_group, 
         ca46, 
         Fabricate(:polco_group, {:name => "Gang of 13", :type => :custom})])