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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:05:38+00:00 2026-05-26T18:05:38+00:00

I really have no idea what to title this so someone PLEASE feel free

  • 0

I really have no idea what to title this so someone PLEASE feel free to edit once you get my drift…

For my example, we have user and book classes.

Each user is one line in our user_data table, each book one line in our book_data table, and each user’s collection can be queried from the one-to-many user_book_collection table.

When I load a user object, I am certain I want all the basic data (name, age, location) but I may or may not want to know the user’s book collection. I probably don’t want to know all the basic data for each book in that collection, but occasionally I might.

But I want all of this available if need be…

RELATIONSHIP MAP

User
  |-- name
  |-- age
  |-- location
  |-- book collection (ARRAY)
        |-- Great Gatsby
        |-- Grapes of Wrath
        |-- Catch-22
        |-- Huckleberry Finn
              |-- author
              |-- edition
              |-- publisher
              |-- price

My current approach is to load the first “tier” of data via the user’s constructor. And then if I need to know his collection for something, I have a method pair like this:

public function getBookCollection() {
    if (empty($this->_Books)) {
        self::loadBookCollection();
    }
    return $this->_Books;
}

private function loadBookCollection() {
    // query dbase with user's ID
    // load results into $this->_Books array
}

The empty() check is to avoid repetitive trips to the database to get data for the $_Books array by different methods in the class.

I figured this was better than loading the entire massive tree of data whenever I want to just initialize a user object…

This is a simple example, but I think it’s clear enough.

My questions are:

1) is this the normal way of handling such things? I can imagine situations where this sort of data overlap could just go on and on and on…

2) is there a better way?

Thank you, and someone please take a crack at my title!

  • 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-26T18:05:38+00:00Added an answer on May 26, 2026 at 6:05 pm

    What you’re doing is generally called “Lazy Loading” or “Lazy Initialization” and is a commonly used programming design to help increase performance by delaying the loading of data until your program needs it (if it does at all). So yes, you’re doing it in a sane fashion 😉

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

Sidebar

Related Questions

I really had no idea what to title this question. Assume I have a
I don't really have an idea on how to phrase this question--even the title
Sorry for the poor title. I really have no idea how to describe this
I really have no idea what I did to cause this exception, but I
I really have no idea why I'm struggling with this so much. I'm scraping
I really have no idea how to go about this. So far all I
I have really no idea why I'm asking this as this a really completely
I have a really hard time searching for this, because I have no idea
Sorry about the strange title. I really have no idea how to express it
Sorry, I really have no idea how to phrase this, so apologies for the

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.