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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:51:42+00:00 2026-06-18T15:51:42+00:00

I watched this rails cast http://railscasts.com/episodes/22-eager-loading but still I have some confusions about what

  • 0

I watched this rails cast http://railscasts.com/episodes/22-eager-loading but still I have some confusions about what is the best way of writing an efficient GET REST service for a scenario like this:

Let’s say we have an Organization table and there are like twenty other tables that there is a belongs_to and has_many relations between them. (so all those tables have a organization_id field).

Now I want to write a GET and INDEX request in form of a Rails REST service that based on the organization id being passed to the request in URL, it can go and read those tables and fill the JSON BUT NOT for ALL of those table, only for a few of them, for example let’s say for a Patients, Orders and Visits table, not all of those twenty tables.

So still I have trouble with getting my head around how to write such a

.find( :all )  

sort of query ?
Can someone show some example so I can understand how to do this sort of queries?

  • 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-18T15:51:43+00:00Added an answer on June 18, 2026 at 3:51 pm

    You can include all of those tables in one SQL query:

    @organization = Organization.includes(:patients, :orders, :visits).find(1)
    

    Now when you do something like:

    @organization.patients
    

    It will load the patients in-memory, since it already fetched them in the original query. Without includes, @organization.patients would trigger another database query. This is why it’s called “eager loading”, because you are loading the patients of the organization before you actually reference them (eagerly), because you know you will need that data later.

    You can use includes anytime, whether using all or not. Personally I find it to be more explicit and clear when I chain the includes method onto the model, instead of including it as some sort of hash option (as in the Railscast episode).

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

Sidebar

Related Questions

so I've watched http://railscasts.com/episodes/43-ajax-with-rjs but I have a question: In my view I have
I've watched this video from Google I/O 2009: http://www.youtube.com/watch?v=AgaL6NGpkB8 where Brett shows microblogging example.
I am going to use http-basic-authentication in a rails app. I watched this railscast
I watched this tutorial http://www.youtube.com/watch?&v=jTS7JTud1qQ&t=7m57s and I can get the code to output a
This is a bit complicated but here goes. I have a Rails app that
so I watched this video on youtube ( http://www.youtube.com/watch?v=l_PLHuhlAJU ) on how to make
I watched few videos/webcasts about Oslo but I still fail to see how it
I just watched this: http://blog.mongodb.org/post/38467892360/mongodb-schema-design-insights-and-tradeoffs-from One suggestion that came out of the talk: in
There have been many questions about this, but none of them seem to help.
Ok...I am new to rails so this may be a stupid question but need

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.