Need a suggestion for calculated value

I need a suggestion for a calculated value. I have an order object
with a total in it. I’d like to recalculate the order total during
the checkout process (as user selects shipping, etc.) but after the
checkout is complete, I’d like to store it in the database for
performance and searching reasons.

Does that make sense? Any suggestions on how to pull this off? I was
thinking an alias to the database method and checking the status of a
checkout_complete boolean.


On 6 Sep 2008, at 19:54, schof wrote:

You could do something like

def total
self[:total] || calculate_total

Which does what it says: if there is a non nil total attribute then it
will use that, if not it calculates it.