MrGlass
MrGlass

Reputation: 9262

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()
        ->select('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.

Upvotes: 0

Views: 327

Answers (2)

prodigitalson
prodigitalson

Reputation: 60413

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

Upvotes: 1

Adam Arold
Adam Arold

Reputation: 30528

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()

Upvotes: 1

Related Questions