Working With Related Data Within Controller

Hi guys,

I have a question about the way to retrieve data inside the controller. Supposing that i have two related tables, many to many:


PatientDoctor (Relation table)


In my patient controller i am trying receive the related data from doctor model with this code:




foreach($model->patientdoctors as $doctor)


   $id_doctor = $doctor['id_doctor'];


patientdoctors is the relation in Patient Model. Exist another method to receive the data from relation? Without use a foreach for get the data from array.