Skip to main content

Saving and Closing Objects

After we have updated the Film object, we call its %Save method to store it in the database.

We then set the Complete property of the TicketOrder object to 1 (true) to indicate that this order is complete and save it. Note that we do not have to save the TicketItem objects. Caché does this automatically, when the related TicketOrder object is saved.

ClassMethod CompleteOrder()
    If $data(%session.Data("Order")) {
        // Open the current order object
        Set ord = ##class(Cinema.TicketOrder).%OpenId(%session.Data("Order"))

        // Update the number of tickets sold for each film in the order
        For i = 1:1:ord.Items.Count() {
            Set itm = ord.Items.GetAt(i)
            Set flm = itm.Show.Film
            Set flm.TicketsSold = flm.TicketsSold +
                itm.AdultTickets + itm.ChildTickets
            Set cat = flm.Category.%Id()
            Do flm.%Save()
        // Mark order as complete and save
        Set ord.Complete=1
         Do ord.%Save()
        // ...
FeedbackOpens in a new tab