/** * Creates the rooms and beds for a new floor */ public function create_child_objects($rooms_per_floor, $beds_per_room) { for ($i = 0; $i < $rooms_per_floor; $i++) { $room = new HMS_Room(); $room->floor_id = $this->id; $room->term = $this->term; $room->gender_type = $this->gender_type; if ($room->save()) { $room->create_child_objects($beds_per_room); } else { // Decide on bad Result. } } }