我目前在后端使用 Doctrine 1.2.2 和 MySQL。当我尝试使用记录或延迟加载水合模式检索多个项目的结果集时,只显示一个项目。但是,当我使用阵列水合模式时,我看到了所有结果。始终如一地,只检索结果集中的最后一项。
我误解了 API 吗?模型是否定义不正确(它是自动生成的)。不应该这么简单吗?
现在,我正在启动我的调试器,我将逐步浏览 Doctrine 的源代码。
// Model used:
<?php
/**
* BaseEntryVote
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* @property integer $contest_id
* @property integer $vote_id
* @property integer $entry_id
* @property integer $subcategory_id
* @property string $company
* @property string $website
* @property string $email
* @property string $comments
* @property integer $votes
*
* @package ##PACKAGE##
* @subpackage ##SUBPACKAGE##
* @author ##NAME## <##EMAIL##>
* @version SVN: $Id: $
*/
abstract class BaseEntryVote extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('entry_vote');
$this->hasColumn('contest_id', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => true,
'notnull' => false,
'autoincrement' => false,
));
$this->hasColumn('vote_id', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('entry_id', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'default' => '0',
'notnull' => false,
'autoincrement' => false,
));
$this->hasColumn('subcategory_id', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'default' => '0',
'notnull' => false,
'autoincrement' => false,
));
$this->hasColumn('company', 'string', 100, array(
'type' => 'string',
'length' => 100,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
));
$this->hasColumn('website', 'string', 75, array(
'type' => 'string',
'length' => 75,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
));
$this->hasColumn('email', 'string', 75, array(
'type' => 'string',
'length' => 75,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
));
$this->hasColumn('comments', 'string', 255, array(
'type' => 'string',
'length' => 255,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
));
$this->hasColumn('votes', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
));
}
public function setUp()
{
parent::setUp();
}
}
// Below is the code used to access the doctrine api
/*
Table entry_vote
================
contest_id, vote_id, entry_id, subcategory_id, company, website, email, comments, votes
----------------
contest_id INT
vote_id INT
entry_id INT
subcategory_id INT
company VARCHAR
website VARCHAR
email VARCHAR
comments VARCHAR
votes INT
Data in db:
'0', '1', '1', '0', 'Foo Bank', 'http://localhost/foo', 'bob@foo.com', NULL, '2'
'0', '0', '0', '0', 'TPS Corp', 'http://localhost/tps', 'bob@tps.com', NULL, '1'
*/
$result = Doctrine_Core::getTable('EntryVote')->findAll();
foreach ($result as $entry) {
print $entry->company;
}
/* Here is the query that Doctrine is generating: */
SELECT e.contest_id AS e__contest_id, e.vote_id AS e__vote_id,
e.entry_id AS e__entry_id, e.subcategory_id AS e__subcategory_id,
e.company AS e__company, e.website AS e__website,
e.email AS e__email, e.comments AS e__comments, e.votes AS e__votes
FROM entry_vote e WHERE (e.contest_id = ?)