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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:55:58+00:00 2026-06-18T11:55:58+00:00

I have a complex DB schema in my Rails 2.3 app. At some point,

  • 0

I have a complex DB schema in my Rails 2.3 app. At some point, I need to make a query to retrieve data from several columns by joining multiple tables. There is a table where I always need to go through to retrieve the data I need.

The problem comes when I try to use Rails syntax to make the joins. I found no way to make rails skip joining the same table again and again.

Let’s say I have this table relationships:

A=>B=>C=>D=>E=>F
A=>B=>F=>G
A=>B=>F=>H
A=>I

As you can see, B is a table that I “join” several times to get to the tables I need.

My query looks something like this:

A.all( :select=>"SOME DATA FROM F, G, H AND I",
       :joins=>[{{{{:B=>:C}=>:D}=>:E}=>:F}, {{:B=>:F}=>:G}, {{:B=>:F}=>:H}, :I],
       :conditions=>{"SOME CONDITIONS"
                    }
     )

You can see that I use the hash syntax to specify the joins.

The problem is that when I look at the join that rails create, I see that it joins B 3 times. I would expect that it would be smart enough to do it just just once and go from there but I guess that there maybe cases where you want to join several times.

My question is, how can I, using rails 2.3.8 syntax, make so that the resulting query just joins B once. Adding extra relationships in the model of type :belongs_to :throug is not an option for me

  • 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-18T11:56:00+00:00Added an answer on June 18, 2026 at 11:56 am

    try

    A.all(:joins => [:I, { :B => [{ :F => [:G, :H] }, {:C => { :D => { :E => :F }}}]}])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several complex data structures like Map< A, Set< B > > Set<
I have a complex crm db schema and I need to support google-style type-ahead
I have a complex XSD schema and hundreds of XML files conforming to the
I have a pretty complex database schema and would like to know if there
I have an xml with an xml-schema. The xml-schema defines an abstract complex type
I have some complex message to show inside of a flash message so instead
We have a complex app that serves AJAX JSON streams (using ADO to grab
I have a complex MySQL problem. SELECT * FROM banners, content_id_country, languages WHERE content_id_country.content_id
I have reduced a complex schema to the following samples Students StudentID int, Name
I have 1000s of XML files with complex nested structures. I need to see

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.