Topic: Math between different records

Hi all.

Could you please recommend elegant way (read - best practices in "Rails way", less DB calls) to solve the following situation ?

I have 2 tables:

Meter
- has_many :meter_records

MeterRecord
- belong_to :meter

I have to calculate difference between meter's current month record and same meter's previous month record.

I would like to avoid unnecessary selects from DB and also avoid dealing with SQL - I prefer functionality provided by ActiveRecord.

Can you please recommend the solution or at least point me to a good tutorial ?

Thank you in advance.

Artūras

Last edited by artbar (2011-04-06 14:53:36)