AnsweredAssumed Answered

How to correctly retrieve beams from a module.

Question asked by Enrique Madrigal Gutierrez on Oct 21, 2019
Latest reply on Oct 25, 2019 by Maryam Aslam
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_option->load_relationship('bo01_bookingoptions_bo01_bookingdetails_1'); 
 $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.
$GLOBALS['log']->fatal(count($booking_details));
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);
            {
$GLOBALS['log']->fatal("Loop");
                $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.
for($j=0;$j<count($booking_details);$j++)
{
$GLOBALS['log']->fatal("Loop");
$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.

Outcomes