tags:

views:

76

answers:

1

I'm new to Doctrine but somewhat familiar with SQL. I have a very simple schema with Users and Challenges. Each Challenge has a "challenger id" and a "opponent id" which are foreign keys into the User table. I want to print a list of all challenges, with the output being the names from the User table. Here is my Doctrine query;

$q = Doctrine_Query::create()
        ->select('u1.name challenger, u2.name opponent')
        ->from('Challenge c')
            ->leftJoin('c.Challenger u1')
            ->leftJoin('c.Opponent u2');

The problem is that this only returns one row. I've used the getSqlQuery() command to look at the generated SQL which ends up being:

SELECT u.name AS u__0, u2.name AS u2__1 FROM challenge c 
LEFT JOIN user u ON c.challenger_id = u.id 
LEFT JOIN user u2 ON c.opponent_id = u2.id

When run in a 3rd party SQL client this query retrieves all of the rows as expected. Any idea how I can get all of the rows from Doctrine? I'm using $q->execute() which I understand should work for multiple rows.

Thanks.

A: 

Once I properly fetched the data from the Collection it worked.

LVB