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

  • Home
  • SEARCH
  • 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 523499
In Process

The Archive Base Latest Questions

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

Given three models that are each nested in each other. If I create the

  • 0

Given three models that are each nested in each other. If I create the top-level object and build_* the other child objects, I can retrieve all child objects through the relationships before and after save() on the original instance. However, if I try to retrieve the 2nd level nested object after find(:id) the original parent it fails. I can retrieve the 1st level nested object, however. This usually happens in a controller, but I’ll illustrate it in console output below.

What am I overlooking?

Thanks in advance!
~jpv

>> l = Lead.new :buyer_name => 'Kim Possible', :email => 'kim@possible.com', :phone => '7131231234'
>> l.build_buyer
>> l.buyer.name = 'kim buyer'
>> l.buyer
>> l.buyer.build_contact_detail
>> l.buyer.contact_detail.email = "kim-contact-detail@possible.com"
>> l.save #returns true
>> l.buyer #THIS WORKS
=> #<Buyer id: 1, name: "kim buyer", lead_id: 1>
>> l.buyer.contact_detail #THIS WORKS
=> #<ContactDetail id: 1, company_id: nil, buyer_id: 1, email: nil, address_line_1: nil, address_line_2: nil, city: nil, state: nil, postal_code: nil>
>> l2 = Lead.find(1)
=> #<Lead id: 1, company_id: nil, buyer_id: nil, public_lead_id: nil, buyer_name: "Kim Possible", company_name: nil, email: "kim@possible.com", phone: "7131231234">
>> l2.buyer #THIS WORKS AS EXPECTED
=> #<Buyer id: 1, name: "kim buyer", lead_id: 1>
>> l2.buyer.contact_detail #THIS BREAKS
=> nil

All the boilerplate stuff below:

class Lead
  has_one :buyer
  #...
end

class Buyer
  has_one :contact_detail
  belongs_to :lead
  #...
end

class ContactDetail
  belongs_to :buyer
  #...
end

The appropriate foreign keys are in each of the “belongs_to” classes.

class CreateBuyers < ActiveRecord::Migration
  def self.up
    create_table :buyers do |t|
      t.string :name
      t.integer :lead_id
...

class CreateContactDetails < ActiveRecord::Migration
  def self.up
    create_table :contact_details do |t|
      t.integer :buyer_id
  • 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-13T08:28:08+00:00Added an answer on May 13, 2026 at 8:28 am

    I think you might be getting tripped up because you’re expecting the object to eager load nested child objects. In general, you have to explicitly specify it for that to happen in the find. Try adding :include => [:borrower, {:borrower => :contact_detail}] to the options for the find and see if that works.

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

Sidebar

Ask A Question

Stats

  • Questions 511k
  • Answers 511k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Confusion was due to a typo in the relationship definition… May 16, 2026 at 5:14 pm
  • Editorial Team
    Editorial Team added an answer I had to check "Inherit from parent or project defaults"… May 16, 2026 at 5:14 pm
  • Editorial Team
    Editorial Team added an answer In support of Darin's answer of course you need to… May 16, 2026 at 5:14 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Given class Category(db.Model): name = db.Stringproperty() Say I have a nested hierarchy -root |-a
I thought that there should have been a simple solution to this, given that
I'm having a problem with nested model forms that contain radio buttons, when I
I have a set of objects in a hierachy. There's a top root node
I have several similar Models (ContactEmail, ContactLetter, ContactPostalcard). Each instance (record) in, say, ContactEmail,
I'm engaged in a debate over XML representations of groups of objects. Given an
I'm using nested sets (aka modified preorder tree traversal) to store a list of
I'm importing some content into a Nested Tree model, and I'm implementing a Transaction
I am using hibernate, spring, struts framework for my application. In my application, each
I have an application which has the following characteristics There are Clubs Each Club

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.