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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:41:09+00:00 2026-06-17T14:41:09+00:00

sorry for my beginner question but i’m trying to learn RoR. In Rails 3.2

  • 0

sorry for my beginner question but i’m trying to learn RoR.
In Rails 3.2 i’ve declared:

class Project < ActiveRecord::Base
   attr_accessible :name, :description
   has_many :subprojects
end


class SubProject < ActiveRecord::Base
   attr_accessible :id_name, :description, :num_alloc, :project_id
   belongs_to :projects
end

How can i show, in a view, a table with the attributes id_name, num_alloc (from SubProject) and name (from Project)

How can i make the join?
In the controller, if i make:

@results=  SubProject.joins('LEFT OUTER JOIN.......)

this, return only the SubProject attribute right?

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-17T14:41:10+00:00Added an answer on June 17, 2026 at 2:41 pm

    There is a thing called eager loading. When you make a query with a join, and create the objects, these associations are prepopulated. For example:

    @results = SubProject.joins(:project)
    

    In your view, or any other place, if you call the project object inside subproject, you will have direct access to its content, without making another query.

    @results.each do |r|
      puts r.project.name # The project is prepopulated from the db
    end
    

    If you don’t care about performance, you can just fecth the subprojects and for each one of them query the project inside.

    @results = SubProject.all
    
    @results.each do |r|
      puts r.project.name # This will make other query
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for the beginner question, but I can't figure out cProfile (I'm really new
am sorry for this dumb beginner question, but i have a real problem understanding
sorry if this question is basic but I'm a beginner :(. I've created an
Sorry for asking such a beginner question but I can't figure this out. I
Sorry for asking such an easy question, but im a beginner I was following
Sorry that this is very much a beginner's question, but yes, I'm only just
sorry for the beginner's question, but I find it hard to understand: I have
Hello first sorry if its a stupid question, but I amm a beginner, and
Sorry for the beginner python question, but I cant find anywhere how to do
This is an absolute beginner's question (sorry), but I was wondering how to commit

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.