3
的schema.yml數據庫:太多的查詢來Symfony和學說
JobeetCategory:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true, unique: true }
JobeetJob:
actAs: { Timestampable: ~ }
columns:
category_id: { type: integer, notnull: true }
name: { type: string(255) }
relations:
JobeetCategory: { onDelete: CASCADE, local: category_id, foreign: id, foreignAlias: JobeetJobs }
action.class:
public function executeIndex(sfWebRequest $request)
{
$this->jobeet_job_list = Doctrine::getTable('JobeetJob')
->createQuery('a')
->execute();
}
和模板:
<table>
<?php foreach ($jobeet_job_list as $jobeet_job): ?>
<tr>
<td><?php echo $jobeet_job->getcategory_id() ?></td>
<td><?php echo $jobeet_job->getName() ?></td>
</tr>
<?php endforeach; ?>
</table>
產生這些模板只有2個查詢到數據庫。還行吧。但是,如果我這樣做:
<table>
<?php foreach ($jobeet_job_list as $jobeet_job): ?>
<tr>
<td><?php echo $jobeet_job->getJobeetCategory()->getName() ?></td>
<td><?php echo $jobeet_job->getName() ?></td>
</tr>
<?php endforeach; ?>
</table>
,我已經在數據庫中,然後100 JobeetJob這產生102查詢數據庫!這太多了!有可能減少這個?
渴望取? – Hannes 2012-01-11 10:40:13