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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:45:43+00:00 2026-05-28T02:45:43+00:00

I am trying to retrieve a child object based on the key in its

  • 0

I am trying to retrieve a child object based on the key in its parent’s table. For instance, I have the Customer class which contains a “store_id” key to the Stores tables. If a customer has a “store_id” key, I would like to bring back that Store object and not the parent Customer object.

EDIT: Here is a sql statement showing what I am trying to do.

So the SQL statement would look something like this.

“SELECT storeS.* FROM customers INNER JOIN stores ON customers.store_id = storeS.id WHERE customers.id = ‘9’”

I know the sql is probably wrong, but thats a very concise way to show it.

  • 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-28T02:45:44+00:00Added an answer on May 28, 2026 at 2:45 am

    I am assuming you are using rails with the out-of-the-box configuration (using ActiveRecord).

    By convention, the “store_id” key in the “customers” table should match an “id” field in the “stores” table. You should also have the following class models setup:

    class Store < ActiveRecord::Base
      has_many :customers # this is not required for what you want to do here, but recommended
    end
    
    class Customer < ActiveRecord::Base
      belongs_to :store
    end
    

    Assuming this is true, you can either do this if you have the store key:

    # assuming we have store key == 9
    Store.find(key)
    

    Or you could do this if you already have the customer:

    # assuming we have customer.store_id == 9
    customer.store
    

    Or if you only have the customer key:

    # assuming we have a customer key == 9
    customer = Customer.find(9)
    store = customer.store
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have an aggregate root which consists of say: class Parent { IEnumerable<Child>
I'm trying to access protected variables in a second-child class extended from its parent,
I have a persistent object that has a huge list of child elements. I'm
I've been trying to figure out how to retrieve a list of child pages
trying to retrieve the id column of records that have their checkboxes selected in
Using the peristance manager, how can I retrieve a child object knowing a child
I have a parent class that handles all the UITableview persistent data management and
Is it possible to get the parent object from a child object dynamically? Essentially,
Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I am trying to retrieve a user on Sharepoint's user photo through the WSS

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.