开发者

Retrieve related objects with Doctrine and Symfony

开发者 https://www.devze.com 2023-01-07 06:44 出处:网络
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).

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'l开发者_运维知识库l really appreciate your help.


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

That's it, quite simple :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号