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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:07:02+00:00 2026-05-12T15:07:02+00:00

I am using an objected oriented MVC framework in PHP (Kohana) and have kind

  • 0

I am using an objected oriented MVC framework in PHP (Kohana) and have kind of mashed together a few techniques to get stuff done. Problem is I am not sure how to keep things clean without calling lots and lots of queries per page.

To illustrate my example, I’ll imagine I am designing a stack overflow like site:

I have model class for a question (question_model) as well as one for question finder (question_finder_model).

question_model mainly just contains variables to store the question data, arrays of answer objects and some factory methods. Something like:

class question_model {
    public $question_id,$question_title,$question_body,$answers = array();    
}

The question finder containers an array of question_model objects as well as an array of question ids. The array of ids is populated by find methods in the class and used by other methods. Something like:

class question_finder_model {
    private $question_ids = array();
    public $questions = array() ;   //

    function public find_questions () {
        // executes some SQL to find a list of projects
        // Create a new question_model object for each question and store in $questions
        // for each of these questions store the id in $questions_ids
    }
    function public get_answer_info () {
       // using all the question ids stored in $question_ids:
       // find information about the answers
     }
}

So I use this method for all my models, for example my user model will contain an array of questions objects.

The problem is that it is getting quite hard to handle, for example my question contains many answers and each answer can contain many comments and so on. How can I populate all these objects without having several queries. I mean the easy way would be to just iterate through my array of question objects and call a function stored within the question class which gets the answers info for that object. But then I would be calling 10’s or 100’s of queries per page.

I apologise if this is all abit hazy as the problem is quite difficult to articulate. Any help is appreciate because perhpas my entire pattern is flawed.

  • 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-12T15:07:03+00:00Added an answer on May 12, 2026 at 3:07 pm

    What you are expressing here is one of the most common preoblems
    with naive ORMappers.
    Generating several queries.

    You can read precise description of your problem here: ORMs Done right: (DBA Gripe #3: hidden expensive actions)

    Basically the problem is that you need to several queries for something like this:

    foreach ($questions in $site) {
     foreach ($question as $questions) {
        foreach ($answer in $question){
           foreach ($comment in $answer) {
             echo "$site->title, $question->title, $answer->title, $comment->title";
           }
        }
     }
    

    }

    It gets really slow, really fast.

    What you need to do is to get all the info in one query with the proper Joins.
    And then populate your objects.

    Look for the suggested implementation in the some article: Class::ReluctantORM — mandatory prefetching

    Finally don’t get hang-up trying to get every case right. The Relational model and Object model “impedance mismatch” isn’t a solved problem. So don’t try to solve it perfectly yourself. After all Object-Relational Mapping is the Vietnam of Computer Science

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your tests should isolate and NOT test the MS methods… May 12, 2026 at 8:31 pm
  • Editorial Team
    Editorial Team added an answer Yes there is indeed a cross domain issue. You will… May 12, 2026 at 8:31 pm
  • Editorial Team
    Editorial Team added an answer Do you mean UPDATE users SET fname = 'badooka', lname… May 12, 2026 at 8:31 pm

Related Questions

I am fetching a set of objects from a Core Data persistent store using
Why does constructor ORDER matter in VB.Net? I am building a .Net type library
I am using an ASP.NET MVC project and everytime I add a class to
I am using an authentication attribute on some of my actions in an asp.net
I am using an asp:Calander and I have an object that has a beginning

Trending Tags

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

Top Members

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.