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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:12:59+00:00 2026-05-28T08:12:59+00:00

Working with a relatively large data set I have a situation where I need

  • 0

Working with a relatively large data set I have a situation where I need to load data with an associated table and later on in the process the associated objects need to call back to the first object. However it does not seem to fill in the back-reference to the object and so even using :include it has many sql queries

For example:

class Movie
  belongs_to :title
end

class Title
  has_one: movie
end

First, I load the data via

Movie.all(:include => [ :title ])

This results in two sql queries. One to load all the movies, and the one to load all the titles by id.

Second (for purposes of simple demonstration) I want to use the title to get back the movie.

movies.collect{ |movie|
  cur_title = movie.title
  back_reference = cur_title.movie
}

This is where the problem lies. I’d assume no further queries would be necessary as both sides of the one-to-one relationship where already loaded. However the second line in the collect causes many new queries to load each “movie” within the title. Is there a way to have rails automatically fill in this back-reference within title to avoid the many additional (redundant) queries or can this be done manually in an easy way?

Running under Rails 2.3.12

  • 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-28T08:13:00+00:00Added an answer on May 28, 2026 at 8:13 am

    Rails 3.x has a mechanism called :inverse_of to specify the reverse association.

    namely;

    class Movie
      belongs_to :title, :inverse_of => :movie
    end
    
    class Title
      has_one :movie, :inverse_of => :title
    end
    

    in this case, you will not get the reload.

    In Rails 2.x you may find @h-lame’s parental_control a useful temporary solution.

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

Sidebar

Related Questions

I am currently working on a large project and will relatively soon need a
I am working on a relatively large set of serial code C-code libraries, which
I have a relatively large class that I'm working with and it's all worked
I have been working to deploy a relatively large Rails app (Rails 2.3.5) and
i am working on an iphone project that i need to upload relatively large
I'm relatively new to working with XML and am working with some rather large
I'm working on a project involving enlisting a large number of relatively unskilled workers
I'm working on a relatively simple website with (currently) a single resource. I have
I have a relatively simple site that I'm working up for an intranet environment.
I can't get my head around why this isn't working.. I have a relatively

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.