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 4075604
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:19:09+00:00 2026-05-20T17:19:09+00:00

can someone provide an example or point me to where I can learn how

  • 0

can someone provide an example or point me to where I can learn how to do Factory Girl nested model associations?

A Thread has to have at least one ThreadParticipation

Right now I have my thread in factories.rb as follows:

Factory.define :thread do |thread|
  thread.title             "mythread"
end

How do I then create a ThreadParticipation?

Thanks

  • 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-20T17:19:10+00:00Added an answer on May 20, 2026 at 5:19 pm

    The Getting Started file in the factory_girl source has info on associations.

    Associated instances can be generated
    by using the association method when
    defining a lazy attribute:

    factory :post do
      # ...
      author 
    end
    

    You can also specify a different
    factory or override attributes:

    factory :post do
      # ...
      association :author, :factory => :user, :last_name => 'Writely'
    end
    

    So, in your instance, I would imagine something like this would do:

    Factory.define :thread do |thread|
      thread.title "mythread"
      thread.thread_participation
    end
    
    Factory.define :thread_participation do |ppn|
      ppn.attribute "value"
    end
    

    If you’re using a collection instead of a has_one/belongs_to association, you can create an array as such:

    Factory.define :thread do |thread|
      thread.title "mythread"
      thread.thread_participations { |a| [a.association(:thread_participation)] }
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please point me to a reference which gives a full circle example
Can someone provide an example of drawing an iPhone-like turning wheel using Core Graphics
Can someone provide a short example of how a continue statement can be used
Can someone provide me with information on how to add both vertical and horizontal
I know that there is a lot of similar topics, but still... can someone
I am reasonably new to C++ and have limited experience of templates. At the
How do I submit updates of packages that I use to the ELPA? Can
I need to post some xml to a webservice and I'm trying to use
I need to search a CLOB column and am looking for the best way
I am trying to use Google's Sketchup C++ SDK (latest version) to export a

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.