How to correctly retrieve beams from a module.

Hi, thanks, I was wondering if someone has got this case.
I have a module called bookings and a relationship with another module bookingdetails. The type of relationship is one to many.
I'm trying to retrieve the related beams from the booking module.  For example, I have a case of a booking record which has four related records in the module bookingdetails. (This is happening with all records no only this case.)
First I get the beams.
 $booking_details = $booking_option->bo01_bookingoptions_bo01_bookingdetails_1->getBeans();
*** "bo01_bookingoptions_bo01_bookingdetails_1" is the name of the relationship.
If I log the count of $booking_details I got a "4", which is correct.
But when I try to retrieve the details with a "foreach" statement, in only loops one time, I mean only one interaction, not the four interactions that it should be.
$details = array();
 foreach($booking_details as $booking_detail);
                $details[] = $this->formatBean($api, $args, $booking_detail);  //(Ok, works fine, I'm getting the beam object).
I only get the first detail in the array, what happen with the other 3.
If I use a for -loop, some thing like this, I get the four details, but I can't get the beam object, I'm getting something else that is not the BeamObject like in the case of the "foreach" statement. So I can't do a formatBean.
$booking_detail = $booking_details[$j];
  $details[] = $this->formatBean($api, $args, $booking_detail); //(Throws an error, because is an array what I'm getting).
Do you know why this is happening.
It's suppose that $booking_details should be an array of details beams.. ?
How can I retrieve the other 3 beams correctly..
Thanks for the help.
  • Hi Enrique Madrigal Gutierrez,

    It is not happening due to loop, For the confirmation, I applied the foreach loop on the related beans and it is iterating properly, maybe only thing which is creating the glitch is formatBean, I didn't use it so I didn't know about its purpose, If you will remove the formatBean function from your foreach loop it will iterate exactly 4 times, You can check it, formatBean is causing the issue the is why loop iteration is breaking.