Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8231367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:27:50+00:00 2026-06-07T17:27:50+00:00

I am using Mongoid, Rails and Fabrications and at a total loss with how

  • 0

I am using Mongoid, Rails and Fabrications and at a total loss with how this is happening. Any thoughts very appreciated, but I know this pretty complicated. I just want to fabricate a user and have only four joined groups, but I keep getting eight loaded.

Here is the relevant section of my code

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

When I run @user1.joined_groups.size I get 4, but when I do @user1.joined_groups.map(&:name), I get 8 records:

#<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]>

(where i have replaced all BSON::ObjectId(‘4eab3ca5f11aac2701000009’) statements with ones and removed a lot of the middle code.

The full set of code is available here: https://gist.github.com/1323984

Most bizzarre simply calling map might be causing the problem.

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

Generates this (!):

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

Thanks for any insight! After repeated attempts, I can’t figure out a way in terminal to duplicate this, so I am suspecting the Fabrication gem. (Update: nope, I get this error with standard mongoid objects, so I am totally blaming mongoid.)

Tim

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:27:52+00:00Added an answer on June 7, 2026 at 5:27 pm

    I think the problem might simply be that you are not pushing the groups onto the user correctly. Try using concat or separately shoveling them.

    @user1.joined_groups.concat([common_group,
                             cali_group,
                             ca46,
                             Fabricate(:polco_group, {:name => "Gang of 13", :type => :custom})])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my rails app I'm using mongoid and in the logs before pretty much
I am using mongoid in rails app. rails 3.0.10 ruby 1.9.2p0 When I am
I have a class User in Rails using Mongoid and Devise. I can't seem
Using Mongoid 2.4.5 on Rails 3.2.1 I have a Model Book that has_many :pages
I am currently working on a rails app where we are using mongoid/mongoDB on
I would like to write a query in a Rails model using mongoid, and
I've got a Ruby on Rails app that is using MongoDB for datastorage. Mongoid::Timestamp
Is there any one command in Mongoid to delete an object using id? Something
I have recently been getting my feet wet in MongoDB using Mongoid w/ Rails
I recently played with MongoDB in Rails using Mongoid . I like the ability

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.