views:

26

answers:

1

I searched for a long time, but I don't manage to retrieve two related object in one query. I am using Doctrine and Symfony (uses Doctrine by default).

Here is a part of my schema.yml:

Member:
  columns:
    ...some fields...

Report:
  columns:
    member:       { type: integer, notnull: true }
    ...some fields...
  relations:
    Member:  { onDelete: CASCADE, local: member, foreign: id, foreignAlias: Members }

And this my "basic" request which works to retrieve only the report object:

public function getReports($place,$max = 5) {
    $q = Doctrine_Query::create()
            ->from('Report sr')
            ->where('sr.place = ?',$place)
            ->limit($max)
            ->orderBy('sr.date DESC');
    return $q->execute();
}

A report has been committed by a member in a place. I need to retrieve the member object to display it with his fields but I really don't know how to do that.

If you have a clue or method to do that, I'll really appreciate your help.

+1  A: 
$q = Doctrine_Query::create()
->from('Report sr')
->innerJoin('sr.Members m');

That's it, quite simple :)

DuoSRX
I already tried something like that with some leftJoin but symfony throws exceptions like this :500 | Internal Server Error | Doctrine_Table_ExceptionUnknown relation alias Members
Cyril
For information, I cleared cache and the relation is as pasted in the question
Cyril
Hmmm my mistake, it should be Member, not Members.
DuoSRX
No it should be Members but it don't work...
Cyril
No it's not Members. You relation is called Member. The foreignAlias part is used for reverse-relations. http://www.doctrine-project.org/projects/orm/1.2/docs/manual/defining-models/en#relationships:foreign-key-associations:one-to-many-and-many-to-one
DuoSRX