Note that there are some explanatory texts on larger screens.

plurals
  1. PORails modelling for multiple trades of shares
    text
    copied!<p>I'm trying to model a (very) simple share trading simulator in rails to play with 3.1 and try and learn more about web backend stuff as opposed to UX where I normally sit.</p> <p>so lets say you've got </p> <pre><code>Users (has many transactions) Transactions (belongs to users, companies) Companies (has many transactions) </code></pre> <p>So a User buys a number of shares in a company, and that creates a transaction record with the quantity column reflecting the number of shares bought for that particular transaction, the share price at the time, and a status column indicating whether things were bought or sold. (For simplicities sake, and as this is a learning exercise, lets assume that 1 transaction contains only one buy OR sell event)</p> <p>So lets say the user, for some reason, buys and sells all kinds of strange quantities of the same company.</p> <p>He'll end up with multiple transaction rows, which must be queried and summed in order to figure out </p> <p>for each company</p> <ul> <li>if he owns any shares in it at all</li> <li>how much he owns (all buys - sells)</li> <li>etc.</li> </ul> <p>So my question is, is this model correct for this type of use? It seems cumbersome if I want to, for example, write a page indicating what the user owns. It means running all kinds of sums of to determine if owned, and amount owned. But maybe thats just how these things should be done? Or is there a better way?</p> <p>Would it be better to maintain only one transaction representing 'ownership', and update the columns in it for each company 'owned' and then record individual transactions in a second, transaction_history table that is separated out and joined to transaction?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload