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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:38:14+00:00 2026-06-09T02:38:14+00:00

When there are associated models , it is known that specifying the association in

  • 0

When there are associated models , it is known that specifying the association in both the models will create a cyclic dependency and causes a “stack level too deep” error . So what’s the correct place to specify the relationship ? Please see these simple associations :

class Patient
  has_many :doctors, :through => :join_model
end

class Doctor
  has_many :patients, :through => :join_model
end

also

class User
  has_many :posts
end

class Post
  belongs_to :user
end

In the factories for these models , Which one is the right place to hold the associations ?

  • 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-09T02:38:15+00:00Added an answer on June 9, 2026 at 2:38 am

    there is a section in the factory_girl readme that has an example for a has_many association: https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#associations

    i think there is no golden rule here. i usually have a default factory per model, that has a simple or no relations set and then i have special factories like :user_with_posts that are used for a variety of related tests.
    i also often just build them up myself in the test themselfes create(:user, posts: [create(:some_special_post)])

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

Sidebar

Related Questions

Is there any event associated with Install Components Screen? Something like Next button disabled
Is there any attribute associated with the starting time I can get from the
Background: There are multiple DBPArentProductKEys associated with a POG.ID. I need to count the
Is there any difference or associated risk opening with the following PHP variations? <?
Is there any way to get the previously associated Wifi networks for an Android
Is there a way to get an associated icon in C# without using any
Is there quick way to get the ImageFormat object associated to a particular file
Possible Duplicate: Entity Framework: There is already an open DataReader associated with this Command
Is there a way to use the CompiledQuery.Compile method to compile the Expression associated
Can I avoid the open DataReader exception (There is already an open DataReader associated

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.