tags:

views:

19

answers:

1

my basic database setup is:

User:...  
Info:  
  relations:  
    User: { foreignType:one }

When displaying information on the user it takes: 1 query to find info on the user, and 1 query to find additional info

I want to reduce this to one query that finds both, I assume I need to override a function from BaseUser.class.php, or something along those lines but I'm not really sure what to do.

Thanks!

A: 

Assuming you're using Doctrine, you need to override the findOneBy*** methods in your InfoTable class to join data on retrieval

Class InfoTable extends Doctrine_Table {
   [...]
   public function findOneById($id) 
   {
        $q = $this->createQuery('i')
           ->leftJoin('i.User u')
           ->where('i.id = ?', $id);
        return $q->fetchOne();
    }
}

Doctrine will handle and hydrate the associated object, and save one query.

Benoit
In the actions.class.php page it used the find() function to get the user object. after changing this to use a findOneBy-- this solution worked very nicely
You could have override the find method too, as it is called by findOneBy*** methods, but this way is simpler.
Benoit