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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:17:11+00:00 2026-05-19T12:17:11+00:00

How is this possible? All I have done in the console are create these

  • 0

How is this possible? All I have done in the console are create these objects and associate them. This makes no sense to me. p.jobs.first and j are the same thing. Why does the title method work on j and not on p.jobs.first?

ruby-1.9.2-p136 :031 > p
 => #<Person id: 14, type: "Person", desc: nil, created_at: "2011-01-24 23:53:13", updated_at: "2011-01-24 23:53:13"> 
ruby-1.9.2-p136 :032 > p.jobs.first
 => #<Job id: 18, type: "Job", created_at: "2011-01-24 23:53:36", updated_at: "2011-01-24 23:53:36", entity_id: nil, person_id: 14, company_id: 15> 
ruby-1.9.2-p136 :033 > p.jobs.first.title
 => nil 
ruby-1.9.2-p136 :034 > p.title
 => nil 
ruby-1.9.2-p136 :035 > j
 => #<Job id: 18, type: "Job", created_at: "2011-01-24 23:53:36", updated_at: "2011-01-24 23:53:36", entity_id: nil, person_id: 14, company_id: 15> 
ruby-1.9.2-p136 :036 > j.title
 => "dfkjld" 

NOTE: The name class is abstracted and associated with Job. There is a helper module included with both classes like so.

  def title
    if class_name == "Job" 
      name.value
    elsif class_name == "Person"
      if jobs.empty? then "Unemployed" else jobs.first.title end
    else
      nil
    end      
  end

ruby-1.9.2-p136 :015 > j.name
 => #<Name id: 16, kind: nil, value: "dfklj", name_id: nil, event_id: 19, instrument_id: nil, transaction_id: nil> 
ruby-1.9.2-p136 :016 > j.name.value
 => "dfklj"
  • 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-19T12:17:12+00:00Added an answer on May 19, 2026 at 12:17 pm

    It’s probably a lazy loading issue. p.jobs.first isn’t pulling the ‘real’ data from your system, but using a memoized/cached version of it. And that cached version doesn’t contain a title.

    It could be solved by forcing p to ‘reload its dependencies’. If p is an ActiveRecord object, there is a reload method:

    p.reload
    p.jobs.first
    

    Another possibility is that j has local modifications, but these are not commited – for example, in ActiveRecord, if the title was initially nil and you set it on j without saving / reloading, it will not appear on p.jobs.first:

    > p.jobs.first.title
    nil
    > j = Jobs.find(1) # same job as p.jobs.first.title
    ...
    > j.title = 'blah'
    'blah'
    > j.title
    'blah'
    > p.jobs.first.title
    nil
    

    In order for that to work, you have to save to the database and reload p:

    > j.save
    true
    > p.reload
    p.jobs.first.title
    > 'blah'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is this possible at all? The idea is to have the following: if ($some_statement)
is this possible to do , or do i have to do it all
First of all, is this possible? If so: What challenges would I encounter in
First of all I'm not sure this is even possible, however I need to
I have these container objects (let's call them Container) in a list. Each of
First of all, I want to know if this is possible: let's say I
Is this combination possible at all? If yes, will I still need to buy
I'm curious if this is possible at all since a select * from html
I'm not sure if this is possible at all, but wanted to find out
I need to generate Entities/Object from selected tables - not all. Is this possible

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.