0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Cyril
  • 1,649
  • 1
  • 17
  • 32

1 Answers1

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

That's it, quite simple :)

DuoSRX
  • 4,179
  • 3
  • 26
  • 32
  • I already tried something like that with some leftJoin but symfony throws exceptions like this : 500 | Internal Server Error | Doctrine_Table_Exception Unknown relation alias Members – Cyril Jul 16 '10 at 17:17
  • For information, I cleared cache and the relation is as pasted in the question – Cyril Jul 16 '10 at 17:18
  • Hmmm my mistake, it should be Member, not Members. – DuoSRX Jul 16 '10 at 17:28
  • 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 Jul 16 '10 at 18:30