---
title: "Saving order value to each booking"  
description: "Saving order value to each booking"  
author: "Anonymous User"  
published: 2014-12-28  
updated: 2014-12-29  
canonical: https://www.mindstick.com/forum/12825/saving-order-value-to-each-booking  
category: "ruby on rails"  
tags: ["ruby on rails", "ruby"]  
reading_time: 2 minutes  

---

# Saving order value to each booking

I'm creating a ticket [booking](https://www.mindstick.com/articles/12962/4-important-decisions-to-make-when-booking-your-cruise) app as my sample [project](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects) using [Ruby on Rails](https://www.mindstick.com/forum/12824/create-a-new-ruby-on-rails-application-using-mysql-instead-of-sqlite) 4.1. Three are three models - [Events](https://www.mindstick.com/blog/102/events-in-c-sharp), Tickets and Bookings. Events have many tickets and bookings. Tickets have many bookings and they belong to events. Bookings belongs to events and tickets.\
Tickets model has the price field and bookings model has the order_quantity field. [Right now](https://answers.mindstick.com/qa/36863/what-would-happen-if-gravity-became-5-percent-stronger-right-now), I use a model [method](https://www.mindstick.com/forum/166/webservice-method) total_amount in bookings.rb to display the total price ie. (price * order_quantity) in the bookings show page (@booking.total_amount).\
Now, in the bookings index page, I use a block to list all the details Buyer name, ticket type, [order](https://www.mindstick.com/articles/12276/how-timely-order-deliveries-can-improve-customer-experience) quantity etc. Here, I'd like to show the total amount as well. What's the best way to do it? Do I need to create a total_price [column](https://www.mindstick.com/forum/33860/how-to-calculate-column-summary-in-sql-server) in the bookings table and save the amount in the create [action](https://www.mindstick.com/forum/155752/what-is-action-result-with-its-types)?\
**Bookings Index page looks like this:**\

```
<% @event.bookings.each do |booking| %>              <td><%= booking.buyer_name %></td>              <td><%= booking.email %></td>              <td><%= booking.ticket_id %></td>              <td><%= booking.order_quantity %></td><% end%>
```

## Replies

### Reply by Manoj Bhatt

ActiveRecord will return a collection of model instances when you access the relationship in this way. In other words, when you cycle through the bookings, each one is an instance of your model.\
For this reason, you can just re-use your method:\
<td><%= booking.total_amount %></td>


---

Original Source: https://www.mindstick.com/forum/12825/saving-order-value-to-each-booking

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
