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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:56:12+00:00 2026-06-06T09:56:12+00:00

I am feeling a bit slow when it comes to rails and the Active

  • 0

I am feeling a bit slow when it comes to rails and the Active Record associations… I have two tables.

Table = Rings
Table = Variations with foreign_key => “ring_id”.

class Ring < ActiveRecord::Base
      has_many :variations
end

class Variation < ActiveRecord::Base
      belongs_to :ring
end

So in my “index/list” view i want to display all the rings, and both the variations, and i was thinking it would be possible to do this through one SQL query… however, i have tried the join and the include methods and i think i am just not understanding how they work properly.

So my question is, how would i write a query in my controller, that would pull my “title” and “value” column values from the “variations” and combine them into one simple object for easy looping? Or do i have to loop through all rings and look up the variation values during the loop?

thanks

  • 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-06T09:56:13+00:00Added an answer on June 6, 2026 at 9:56 am

    In your controller:

    @rings = Ring.includes(:variations).all
    

    In index.html.erb:

    @rings.each do |ring|
      ...
      ring.variations.each do |variation|
        ...
      end
    end
    

    The includes portion of the query will prevent Rails from repeatedly querying the database as you loop through and render your rings and variations in the view.

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

Sidebar

Related Questions

Gut-feeling: It looks a little bit like two threads both try to initialise disk-based
I have a feeling my problem is a bit strange, but here goes... I
I'm still a bit of a n00b when it comes to rails, however, I
I have a feeling I'm going about this all wrong. But anyway. I have
I have a feeling I'm asking a stupid question here. I'm having trouble retrieving
I have a feeling this XML is not valid, can someone please explain why?
This question is a bit rhetorical. At some point i got a feeling that
i'm having a bit of confusion with property accessors. I'd like to have an
I have a feeling I may already know the answer to this question, but
I am relatively new to php and have a feeling that I am going

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.