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.

1 Answer 1

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

That's it, quite simple :)

Sign up to request clarification or add additional context in comments.

4 Comments

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
For information, I cleared cache and the relation is as pasted in the question
Hmmm my mistake, it should be Member, not Members.
No it's not Members. You relation is called Member. The foreignAlias part is used for reverse-relations. doctrine-project.org/projects/orm/1.2/docs/manual/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.