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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:47:31+00:00 2026-05-27T19:47:31+00:00

Hi I had a query is it a good idea to access one model

  • 0

Hi I had a query is it a good idea to access one model through multiple models. For ex

I have 5 models as

Class A
    belongs_to :b
end 

Class B
    belongs_to :c
  has_many :a
end 

Class C
    belongs_to :d
  has_many :b
end 

Class D
    belongs_to :e
  has_many :c
end 

Class E
  has_many :d
end 

Now If I have a object of class E and I want to get the ojects of class A related to E, is it a right way to do this ….. Or should I add a relation between class E and some other class(B/C)

  • 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-27T19:47:32+00:00Added an answer on May 27, 2026 at 7:47 pm

    It’s really up to you. If you find yourself chaining these together and accessing them through a chain often, ask yourself if the relationship is accurate.

    For instance, if I said my house has many rooms and a room has many doors, I could do this:

    house.rooms.first.doors.first
    

    But if I do that often, I obviously care about that the doors belong to the house. In this case I would rather be able to say:

    house.doors.first_on_floor(2)
    

    You can do this with

    has_many :doors, :through => :rooms
    

    Hope this helps!

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

Sidebar

Related Questions

I'm trying to optimize query performance and have had to resort to using optimizer
As I had written in title, I have SQL query, run on Oracle DB,
I have a webpage that takes 10 minutes to run one query against a
I have a thorny question about transforming Linq Expressions. I had a good search
I have had a good think and just can't get my head around this.
A while ago I had a query that I ran quite a lot for
yesterday you had taught me to query record history within a time range here
Had a good search here but can't see anything that gets my mind in
I have a query which can be expressed 2 different ways with the same
I've had quite a few problems and know that I can get some good

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.