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 wha开发者_Python百科t to do.
Thanks!
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.
精彩评论