views:

41

answers:

1

I'm currently using Doctrine 1.2.2 with MySQL on the backend. When I attempt to retrieve a result set for more than one item using the record or lazy load hydration modes, only a single item shows up. However, when I use the array hydration mode, I see all of the results. Consistently, only the last item in the result set is retrieved.

Did I misunderstand the API? Is the model defined incorrectly (it was autogenerated). Shouldn't it be this simple?

Right now, I'm firing up my debugger and I will be stepping through Doctrine's source code.

// 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', '[email protected]', NULL, '2'
'0', '0', '0', '0', 'TPS Corp', 'http://localhost/tps', '[email protected]', 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 = ?)
+2  A: 

Thanks to the nice folks on the #doctrine irc channel, I have this working now.

The source of the problem was that I did not have auto-increment set on the primary key of the vote table. So, if you are having similar problems, make sure that whatever column that you choose to have as your primary key in your model also has the auto-increment bit set in the database schema.

Elijah