Best approach to complex form - has many through

Hi All,

I currently have 3 models with the following relationships:

EquipmentBooking has many Equipment through EquipmentRequest

Equipment has many EquipmentBooking through EquipmentRequest

EquipmentRequest belongs to EquipmentBooking and Equipment

EquipmentRequest also has a qty property in the model for the number of a set piece of equipment required.

I’ve created a form to handle the booking component and thats fine, but wondering how I should approach the building of the has many through relationship ensuring Im saving the relationships and the qty.

Is a nested form the best way to approach? Currently have the following code in my action and it feels off

if (isset($_POST['EquipmentBooking'])) {

            $booking = new EquipmentBooking;

            $booking->attributes = $_POST['EquipmentBooking'];

            $booking->equipment = $_POST['EquipmentBooking']['equipment'];

            $id  = $booking->save();


                $equipmentRequest = new EquipmentRequest();

                $equipmentRequest->booking_id = $id;

                $equipmentRequest->equipment_id=  $model->equipment;

                $equipmentRequest->qty = 4;