ruby on rails - How to sum effectively -


Before I start, I apologize for a bad title but I did not come with one who Tells the question satisfactorily. If you come up with a better title, then I will gladly switch.

Suppose I have a account model and a transaction model, and I would like to take one yoga as a single parameter, a What is an effective way to do this for applying the account # days_sons_blanes_v_a_list_list?

Here's some sample code:

  class transaction  

Should I use some smart SQL clause, or perhaps ActiveRecord :: Calculations? All transactions are loading and moving backwards towards the head seems like a very bad idea (especially because many transactions can happen). And if I have stuck to the last point of view, do you think that the batch will be smart to regain the transaction.

What this should be (updated):

  # We have the following transactions (unless 00.00 is not there, Time is unimportant) # days ago 0 1 2 3 4 5 6 7 # zodiac -20 10 -60 -30 50 50 -100 100 account.balance == 0 # true days_since_balance_was (100) == 3 # true  

So, how do you solve this problem?

Because SQL is included, it should not be difficult. Some on the lines of:

  SELECT t1. T1 On Left Transactions T2 On T2 On Time Join Transactions Time & lt; T1.time HINGING SUM (T.Amm) & gt; = 100 Group by T.ID, T.time ORDER BY T. TIME LIMIT 1  

Apply or create it using either AR View your database.


Comments