Accessing Doctrine related field from JOIN
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.
精彩评论