开发者

Accessing Doctrine related field from JOIN

开发者 https://www.devze.com 2023-02-13 01:45 出处:网络
I am attempting to pull a list of users using doctrine, with a join, from my database. I have the following function in my model:

I am attempting to pull a list of users using doctrine, with a join, from my database. I have the following function in my model:

public function getAttendees() {
    $q = Doctrine_Query::create()
        ->sele开发者_如何学Cct('a.id, a.name, a.url, m.id')
        ->from('Attendees a')
        ->leftJoin('a.Meetings m WITH m.Meeting_Slot_ID = ?', $this->getId());

    return $q->execute();
}

I've checked the SQL generated by this query, and it is gabbing all the data I want. I am now trying to access the data retrieved. I have the following working:

foreach($object0>getAttendees() as $attendee){
    echo $attendee->getName();
}

However, I can't figure out how to access the m.id field.


I think you can do this:

$attendee->getMeetings()->getId()

You have to use the alias you defined in your schema.yml (if you are using symfony) Generally Doctrine uses this way to chain related models together: model1->model2->model3 ...->getModel2()->getModel3()->getModel3Field()


$attendee->getMeeting()->getId(); OR soemthing to that effect depending on how you have your relations/properties named.

0

精彩评论

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