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

  • SEARCH
  • Home
  • 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 6642463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:56:01+00:00 2026-05-25T23:56:01+00:00

Let’s say you have the following mongoid documents: class User include Mongoid::Document embeds_one :name

  • 0

Let’s say you have the following mongoid documents:

class User
    include Mongoid::Document
    embeds_one :name
end

class UserName
    include Mongoid::Document
    field :first
    field :last_initial

    embedded_in :user
end

How do you create a factory girl factory which initializes the embedded first name and last initial? Also how would you do it with an embeds_many relationship?

  • 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-05-25T23:56:01+00:00Added an answer on May 25, 2026 at 11:56 pm

    I was also looking for this one and as I was researching I’ve stumbled on a lot of code and did pieced them all together (I wish there were better documents though) but here’s my part of the code. Address is a 1..1 relationship and Phones is a 1..n relationship to events.

      factory :event do
        title     'Example Event'
    
        address  { FactoryGirl.build(:address) }
        phones    { [FactoryGirl.build(:phone1), FactoryGirl.build(:phone2)] }
      end
    
      factory :address do
        place     'foobar tower'
        street    'foobar st.'
        city      'foobar city'
      end
    
      factory :phone1, :class => :phone do
        code      '432'
        number    '1234567890'
      end
    
      factory :phone2, :class => :phone do
        code      '432'
        number    '0987654321'
      end
    

    (And sorry if I can’t provide my links, they were kinda messed up)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Mongoid, let's say I have the following classes: class Map include Mongoid::Document embeds_many
Let's say I have the following HTML: <table id=foo> <th class=sortasc>Header</th> </table> <table id=bar>
Let's say I have the following class: public class Test<E> { public boolean sameClassAs(Object
Let's say I have the following class X where I want to return access
Let's say I have the following ruby code : def use_object(object) puts object.some_method end
Let's say I have the following table: CustomerID ParentID Name ========== ======== ==== 1
Let's say I have following classes. (only most important things included) public class Client
Let's say we have following this: <p class=first>This is paragraph 1.</p> <p class=second>This is
Let's say I have the following two classes: public class Person { public string
Let's say I have the following class: class Foo { public: Foo() { Bar();

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.